CSS Grid Generator
A free CSS grid builder that outputs grid-template-areas CSS — the approach professionals use, not just grid-column: span X. Paint named areas by clicking and dragging, set per-track column and row sizes independently, pick from real-world presets, then copy production-ready CSS. No signup required.
Columns
Rows
Column gap
Row gap
Column sizes
Each column can have its own track size. Use fr for flexible, px for fixed, auto, or minmax().
Row sizes
Set a size for each row. auto is ideal for header/footer rows that size to their content.
Click and drag on the canvas to create your first named area.
Name this area:
Letters, numbers, hyphens only. No spaces.
justify-items
Aligns all items along the inline (column) axis.
align-items
Aligns all items along the block (row) axis.
justify-content
Distributes the column tracks within the container.
align-content
Distributes the row tracks within the container.
place-items: center sets both align-items and justify-items in one declaration.
Click and drag on the grid to paint named areas · Or pick a preset above
Container properties
- display
- grid | inline-grid
- grid-template-columns
- Track sizes for columns
- grid-template-rows
- Track sizes for rows
- grid-template-areas
- Named area map as quoted strings
- gap / column-gap / row-gap
- Space between tracks
- justify-items / align-items
- Align items within their cell
- justify-content / align-content
- Distribute tracks in container
Item properties
- grid-area
- Assign to a named area
- grid-column
- start / end (e.g. 1 / 3)
- grid-row
- start / end (e.g. 2 / 4)
- justify-self
- Override justify-items for one item
- align-self
- Override align-items for one item
- place-self
- Shorthand for align-self + justify-self
Track size values
- 1fr
- One fraction of available space
- auto
- Size to content
- 200px
- Fixed pixel size
- minmax(200px, 1fr)
- At least 200px, can grow
- repeat(3, 1fr)
- Three equal columns
- repeat(auto-fill, minmax(240px, 1fr))
- Responsive auto columns
Common patterns
- Holy Grail
- cols: 200px 1fr 160px; rows: auto 1fr auto
- Sidebar layout
- cols: 240px 1fr; rows: 1fr
- Equal 3-col
- cols: repeat(3, 1fr)
- Responsive cards
- repeat(auto-fill, minmax(240px, 1fr))
- Perfect centering
- place-items: center; min-height: 100vh
What is CSS Grid?
CSS Grid Layout is a two-dimensional layout system for the web — it lets you control rows and columns simultaneously, making it the right tool for overall page structure. Unlike Flexbox, which works along a single axis at a time, Grid gives you a coordinate system where items can be explicitly placed anywhere across rows and columns. That's what makes it ideal for defining the skeleton of a page: the header, sidebar, main content area, and footer can all be positioned in a single declaration, without floats, positioning hacks, or nested containers.
Set display: grid on a container and its direct children become grid items that respond to the grid's rules. CSS Grid is fully supported in every modern browser (Chrome, Firefox, Safari, Edge) without vendor prefixes and has been Baseline available since 2017.
How to use this free CSS grid builder
Start with a preset (Holy Grail, Blog, Dashboard) to load a real-world layout instantly — then customise from there. Use the Grid tab to set the number of columns and rows, adjust the gap between tracks, and set a custom size for each track independently. Switch to the Areas tab to paint named grid areas: click on any empty cell in the canvas, drag to another cell to define a rectangular region, release, and type a name. The Align tab controls how items sit within their grid cells and how the tracks distribute within the container. When your layout looks right, copy the CSS (which includes grid-template-areas) or the semantic HTML.
Understanding grid tracks
A track is a single column or row in a CSS Grid. Each track has a size that controls how much space it occupies. The most important unit is 1fr — the fractional unit. One fr represents one fraction of the available space after all fixed-size and auto tracks are placed. Three equal 1fr columns divide all available width into thirds; 2fr 1fr gives the first column twice the space of the second. The fr unit distributes remaining space — so 200px 1fr 1fr allocates 200px to the first column and splits the rest equally.
Other useful track sizes:
auto— the track sizes to fit its content; ideal for header and footer rows that should be as tall as their text.200px— a fixed pixel size; use for sidebars or navigation panels that should not flex.minmax(200px, 1fr)— at least 200px, can grow to fill available space. The go-to for responsive column layouts.repeat(3, 1fr)— shorthand for three equal tracks; equivalent to1fr 1fr 1fr.repeat(auto-fill, minmax(240px, 1fr))— creates as many columns as fit at 240px each, then stretches them to fill remaining space. The standard responsive card grid pattern — no media queries needed.
How grid-template-areas works
grid-template-areas is a CSS property that lets you name rectangular regions of your grid using a visual ASCII-like map. Each quoted string represents one row; names in the same position across adjacent rows merge into a single area spanning those rows. A dot (.) marks an empty cell that belongs to no named area.
Example for a classic blog layout:
.layout {
display: grid;
grid-template-columns: 1fr 300px;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header"
"article sidebar"
"footer footer";
gap: 24px;
}
.header { grid-area: header; }
.article { grid-area: article; }
.sidebar { grid-area: sidebar; }
.footer { grid-area: footer; }
This approach produces semantic, self-documenting CSS where the visual layout map directly mirrors what renders in the browser. It is far easier to maintain than coordinate-based shorthand like grid-column: 2 / 4; grid-row: 1 / 3. The only constraint: every named area must form a contiguous rectangle. L-shapes, T-shapes, and discontinuous spans are invalid and will silently cause the entire grid-template-areas declaration to be ignored.
Grid vs Flexbox: when to use which
CSS Grid and Flexbox are complementary tools designed for different scenarios. Grid is two-dimensional — use it for the overall page structure where you need to control both rows and columns simultaneously. Flexbox is one-dimensional — use it for components within the grid where items flow along a single axis: navigation bars, card headers, button groups, and tag lists.
The standard pattern is to combine both: CSS Grid defines the page skeleton (header, sidebar, main, footer), and Flexbox handles the layout inside each area. For example, the navigation bar inside the header uses display: flex; justify-content: space-between; align-items: center, while the page itself uses CSS Grid with named areas. See the CSS Flexbox Generator for the inner-component side of this pattern.
Frequently asked questions
1fr is the fractional unit — one fraction of the available space after all fixed-size and auto tracks are placed. If you have three columns set to 1fr 1fr 1fr, each gets one-third of the available container width. If you use 2fr 1fr, the first column gets twice the space of the second. The fr unit distributes remaining space — so 200px 1fr 1fr gives 200px to the first column and divides the rest equally between the other two.
grid-template-areas lets you name rectangular regions of your grid using a visual map. Each quoted string represents one row; names in the same position across adjacent rows span those rows. A dot (.) marks an empty cell. Example: "header header" "sidebar main" "footer footer" creates a 2-column, 3-row grid with a full-width header and footer, and a sidebar/main split in the middle. Then assign each element to its area with grid-area: header (no quotes). Every named area must form an exact rectangle — irregular shapes silently invalidate the entire declaration.
place-items: center on the container — this is shorthand for align-items: center; justify-items: center. To center the grid tracks themselves within the container (useful when the grid is smaller than its container), add place-content: center. For a single element perfectly centered in a full-viewport layout, use display: grid; place-items: center; min-height: 100vh on the wrapper — no additional item properties needed.
gap is shorthand for row-gap and column-gap together. Writing gap: 16px sets both to 16px. Writing gap: 16px 24px sets rows to 16px and columns to 24px. Use column-gap and row-gap independently when you want different values for the two axes — for example, a tighter row gap for cards and a wider column gap for readability. Note: gap applies only between tracks — it does not add space around the outer edges of the grid.
minmax(min, max) defines a track that is at least min and at most max in size. It is most powerful combined with auto-fill: grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) creates as many columns as fit at 240px each and stretches them to fill the remaining space. This is the standard responsive card grid pattern — no media queries needed. A single-value shorthand: minmax(0, 1fr) is equivalent to 1fr but ensures the track can shrink to zero, which prevents overflow in edge cases involving content with a natural min-width.
grid-area value must exactly match the name in grid-template-areas, case-sensitive. (2) Non-rectangular area — CSS requires every named area to be a perfect rectangle; an L or T shape silently invalidates the entire grid-template-areas declaration. (3) Missing grid-area on the item — defining areas on the container alone does nothing; each child must also declare grid-area: name. (4) Alignment not stretching — if justify-items or align-items is not stretch (the default), items size to their content rather than filling the area.
grid-template-areas has been universally supported since 2017 as well. You do not need a polyfill or fallback for any actively supported browser. Internet Explorer 11 had a partial, older implementation (-ms-grid), but IE11 reached end-of-life in 2022 and is not a concern for new projects.