CSS Grid Generator
The CSS Grid Generator builds grid layouts visually: per-track sizing in fr, px, %, auto, min-content, max-content or minmax(), row and column gaps separately, a drag-to-paint named-areas canvas that writes the grid-template-areas ASCII art, five real-world presets, and a live preview that IS a real CSS grid — plus clean CSS, the matching HTML, and Tailwind v4 output. No subgrid in v1, and the page says so.
How to Use
- 1
Start from a preset — Holy Grail / page layout, 12-column, photo gallery, dashboard, or magazine — or build from the defaults (3×2 of 1fr tracks). A preset is a real-world starting point, not a blank canvas.
- 2
Set the columns and rows (1–12 each), then size each track by hand: fr, px, %, auto, min-content, max-content, or minmax(). Identical tracks collapse to repeat() in the output — three 1fr columns become repeat(3, 1fr).
- 3
Set the row gap and column gap separately (0–64px). Equal gaps collapse to one gap line in the CSS; different gaps emit row-gap and column-gap separately.
- 4
Paint named areas on the canvas: type an area name, then drag across cells — the tool writes the grid-template-areas ASCII art for you. Erase mode clears cells back to dots. The live preview places each named area by grid-area, so what you see is what the code does.
- 5
For a gallery that reflows, switch Responsive columns to repeat(auto-fit, minmax()) and set the minimum track width — columns appear and disappear as the container narrows. auto-fit collapses the empty tracks so items stretch; auto-fill keeps them as blank space.
- 6
Copy the CSS — the container rule, one rule per named area, and the ≤640px stacked-mobile media query when enabled — or switch to the HTML tab for the matching skeleton, or Tailwind v4 for the same layout as utility classes. If you need a one-dimensional row or column instead, use the CSS Flexbox Generator.
Frequently Asked Questions
What is CSS grid?
Flexbox vs CSS grid — which should I use?
What is the fr unit?
What is grid-template-areas?
How do I make a responsive grid?
What is the difference between auto-fill and auto-fit?
What is minmax()?
Does this support subgrid?
Is the Tailwind output guaranteed to work?
Can grid center a div?
Generative Answer & AI Documentation
What is the CSS Grid Generator?
The CSS Grid Generator is a visual builder for CSS grid layouts. A grid container (display: grid) places its children into rows and columns at the same time, using grid-template-columns, grid-template-rows, and optionally grid-template-areas — and this page exposes all of them as controls, with a live preview that applies the exact settings the output contains. Columns and rows run 1–12 each, and every track is sized individually: fr, px, %, auto, min-content, max-content, or minmax(). Row gap and column gap are separate sliders (0–64px). The named-areas canvas lets you drag across cells to paint areas — type a name, paint the cells, and the tool writes the grid-template-areas ASCII art, one quoted row per grid row, with dots for empty cells. Five presets — Holy Grail / page layout, 12-column, photo gallery, dashboard, magazine — are real-world starting points. The responsive mode switches the columns to repeat(auto-fill, minmax()) or repeat(auto-fit, minmax()), and the mobile-stack option emits a ≤640px media query that puts every area in one column. The output is clean CSS (the container rule, one rule per named area, and the mobile media query), the matching HTML skeleton, and the same layout as Tailwind v4 utility classes. Grid is two-dimensional by design: for a one-dimensional row or column, use the CSS Flexbox Generator on this site instead — the two pages cross-link in both directions with the 1-D vs 2-D rule.
Why use CSS Grid Generator offline?
Grid is easy to describe and fiddly to get right by hand: the difference between auto-fill and auto-fit is invisible until the last row, the fr unit is misunderstood more than any other CSS unit, and writing grid-template-areas by hand means counting columns in a text editor. A visual builder collapses that loop: paint the areas, see the layout move, copy the CSS. The second reason is the per-track sizing. Most online grid generators are three-control boxes — columns, rows, gap — which makes them demos, not tools: a Holy Grail layout needs 200px 1fr 200px with auto 1fr auto rows, and a dashboard needs a fixed sidebar plus growing columns, and neither can be built from a column count alone. This page ships per-track controls, and the presets prove it. The third reason is the output discipline: identical tracks collapse to repeat(), equal gaps collapse to one gap line, and named areas get one rule each — so the CSS you paste is the minimal description of the layout you built. And because the preview is the browser's own layout engine applying the same settings the CSS contains, the output is verified by construction: if the preview looks right, the code is right.
When should you use this tool?
Use it when you need a page layout (header, sidebar, content, footer — the Holy Grail preset), a 12-column page grid, a dashboard with a sidebar and stat cards, a magazine layout with a feature story spanning two columns, or a photo gallery that reflows as the viewport narrows. Use it when you are learning grid: the fr / repeat() / minmax() cheat-sheet on this page, plus the live preview, teaches the track model faster than any reference table. Use it when you are prototyping a page and want the CSS in one pass instead of five edit-refresh cycles. Do not use it for one-dimensional layouts — a navbar, a card row, a toolbar — that is flexbox's job, and the flexbox generator is the stated alternative. Do not treat the output as finished responsive design either: the generated grid is the desktop layout, and the stacked-mobile media query is the one responsive behaviour the tool owns — everything else at small widths is still yours.
Key Benefits
- Five real-world presets — Holy Grail, 12-column, photo gallery, dashboard, magazine — not a blank canvas.
- Per-track sizing: fr, px, %, auto, min-content, max-content, minmax() on every column and row.
- Drag-to-paint named-areas canvas — the grid-template-areas ASCII art is written for you.
- Row gap and column gap separately, 0–64px each.
- repeat(auto-fill | auto-fit, minmax()) responsive mode, with the auto-fill-vs-auto-fit difference explained on the page.
- Live preview that IS a real CSS grid, driven by the same settings as the output.
- Clean CSS + HTML skeleton + Tailwind v4 output, with arbitrary values for off-scale tracks so the class always means the chosen sizes.
- Stacked-mobile media query (≤640px) that puts every named area in one column.
- 100% client-side: no signup, no upload, no build step.
Common Use Cases
- Building a Holy Grail layout: pick the preset (200px 1fr 200px, auto 1fr auto, header/sidebar/content/ads/footer areas) and copy the CSS — the three-line ASCII art is the whole layout.
- Building a 3-column photo gallery that reflows: pick the gallery preset (auto-fit + minmax(200px, 1fr)), and columns appear and disappear as the container narrows.
- Building a 12-column page grid: pick the preset, place content by spanning columns, and align every section to the same twelve tracks.
- Building a dashboard: pick the preset — fixed 220px nav, header across the top, three stat cards, main content below — and the named areas place every block.
- Learning the fr unit: set the tracks to 200px 1fr 200px, resize the preview, and watch the middle column take whatever free space remains.
Developer Notes & Best Practices
The generator is pure string building with no DOM dependency, which is why its output is unit-tested in Node. The container's inline style for the preview and the CSS text for the output are both derived from the same settings object: gridContainerStyle() returns the React style (display: grid plus the track lists, gaps, and the areas string), and generateGridCss() emits the same values as CSS text. Identical tracks collapse to repeat() (three 1fr columns become repeat(3, 1fr)); equal row and column gaps collapse to one gap line, different gaps emit row-gap and column-gap separately; named areas are emitted as one quoted row per grid row with the semicolon on the last row only, plus one .name { grid-area: name; } rule per area. The mobile-stack option appends a @media (max-width: 640px) block that re-lists the areas in one column (or a single 1fr column when there are no areas). The Tailwind v4 mapping is explicit: equal 1fr tracks become grid-cols-N, anything else uses an arbitrary value (grid-cols-[200px_1fr_200px]) so the class always means exactly the chosen tracks, gaps use the spacing scale (gap-4 = 16px) with arbitrary values off-scale, and named-area items use the [grid-area:...] arbitrary property because Tailwind has no plain class for grid-template-areas. The CSS-generation function is covered by Node tests: the default grid emits repeat(3, 1fr) and repeat(2, 1fr); the Holy Grail preset's ASCII art matches its areas; auto-fit emits repeat(auto-fit, minmax(200px, 1fr)); and the Tailwind classes for equal tracks are grid-cols-3. Two honest limits are stated on the page: no subgrid is emitted in v1, and the Tailwind output is a convenience mapping checked against Tailwind v4, not a guarantee for other versions.
The track-sizing cheat-sheet
| Size | What it means | When to use it |
|---|---|---|
| 1fr | One share of the FREE space (after fixed tracks and gaps) | Equal columns, flexible middles |
| 200px | Exactly 200 pixels, whatever the container | Sidebars, fixed panels |
| 25% | A quarter of the container | Proportional splits |
| auto | Sized by the content | Rows that fit their content |
| min-content | The smallest the content allows | Preventing overflow |
| max-content | The largest the content needs | Letting content decide |
| minmax(200px, 1fr) | At least 200px, at most a share of free space | Reflowing galleries |
auto-fill vs auto-fit — the #1 confusion
| auto-fill | auto-fit | |
|---|---|---|
| Empty tracks | Kept — blank space stays at the end of the row | Collapsed to zero — items stretch to fill the row |
| Full rows | Identical to auto-fit | Identical to auto-fill |
| Use it when | You want the grid to keep its shape with few items | You want items to stretch and fill the row |
Flexbox vs CSS grid
| Flexbox | CSS grid | |
|---|---|---|
| Dimensions | One (row OR column) | Two (rows AND columns) |
| Best for | Navbars, card rows, centering, toolbars | Page layouts, dashboards, galleries |
| Content vs layout | Content decides the layout | Layout decides the placement |
| Use together | Flexbox inside grid cells | Grid cells containing flex rows |
| This page | No — the CSS Flexbox Generator on this site | Yes — this generator |
- Start from a preset, then tune — the presets encode the common patterns (Holy Grail, dashboard, gallery) so you do not rediscover them.
- Remember what fr means: a fraction of the FREE space, after fixed tracks and gaps — 200px 1fr 200px gives the middle column whatever remains.
- Name your areas: a layout drawn as "header header header" is readable six months later; a layout of line numbers is not.
- Use auto-fit + minmax() for galleries and auto-fill when you want the grid to keep its shape with few items — the difference only shows on the last, partly-filled row.
- Check the stacked-mobile output before shipping: the ≤640px media query is the one responsive behaviour the tool owns, and it stacks every area in order.
- Copy the Tailwind output only after checking it against your Tailwind version — the mapping is checked against v4.
Common Mistakes
- Treating fr as a fraction of the whole container: it is a fraction of the FREE space — fixed tracks and gaps come out first, and only then is the remainder shared.
- Using grid for a one-dimensional row: a navbar is a flexbox job — grid will fight you, and the layout will be fragile.
- Confusing auto-fill and auto-fit: they are identical on full rows and differ only when there are more tracks than items — auto-fill leaves blank space, auto-fit stretches the items.
- Writing grid-template-areas by hand and miscounting columns: every quoted row must have the same number of cells, or the whole declaration is invalid — the painter on this page cannot miscount.
- Expecting the generated grid to be responsive by itself: without auto-fit/minmax or the stacked-mobile query, the column count stays fixed at every width.
- Forgetting the gap in the fr maths: gaps are subtracted before fr shares the free space, so a 16px gap on a 3-column grid takes 32px out of the free space first.
Limitations
Grid is two-dimensional: it controls rows and columns together, and it cannot do what flexbox does best — distributing space along one axis with content-driven sizing — so a navbar or a card row belongs in the flexbox generator, and this page says so. The generated grid is the desktop layout: the stacked-mobile media query is the one responsive behaviour the tool owns, and every other breakpoint is still yours. No subgrid is emitted in v1 — a nested grid cannot share its parent's tracks from this output. The Tailwind v4 output is a convenience mapping, not a guarantee: class names were checked against Tailwind v4, and other versions (notably v3) may differ, and grid-template-areas itself has no plain Tailwind class — it still comes from the CSS tab. The preview is capped at 12×12 tracks; a real page's grid is whatever your design needs.
Structured Input/Output Example
Preset: Holy Grail — or tracks chosen by hand: columns: 200px 1fr 200px · rows: auto 1fr auto · gap: 16px areas: "header header header" "sidebar content ads" "footer footer footer"
.grid-container {
display: grid;
grid-template-columns: 200px 1fr 200px;
grid-template-rows: auto 1fr auto;
gap: 16px;
grid-template-areas:
"header header header"
"sidebar content ads"
"footer footer footer";
}
.header { grid-area: header; }
— plus the matching HTML skeleton, or the Tailwind v4 version:
<div class="grid grid-cols-[200px_1fr_200px] gap-4">…</div>Related Tools
CSS Flexbox Generator
CSS flexbox generator: build layouts visually — presets, live preview, container and per-item controls, clean CSS + HTML and Tailwind v4 output. No signup.
CSS Gradient Generator
CSS gradient generator with linear, radial, conic and mesh/aurora gradients — live preview, presets, Tailwind output and PNG export. 100% offline.
CSS Box Shadow Generator
CSS box shadow generator: build layered shadows visually — presets, 3-background preview, CSS + Tailwind output, edit an existing shadow. Free, offline.
CSS Beautifier
CSS beautifier: untangle minified stylesheets into readable CSS — one rule per line, properties indented, selectors aligned. Free, offline, private.
Color Palette Generator
Color palette generator: one base color in — a 5-color harmony palette plus a 50–950 Tailwind scale. Lock, shuffle, copy HEX/RGB/HSL, export CSS or JSON.