Layout templates
Drag across the dashed cells to place an item that spans them. Name items to use grid-template-areas.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 100px);
gap: 12px;
}Placed items (0)
No items placed yet. The output then uses auto-placement with one div per cell.
How to use
Start from a template or set tracks
Click a layout template, or enter Columns and Rows from 1 to 12 and type each track size, such as 240px, 1fr or minmax(80px, auto). Set all to fills every track at once.
Drag to place and name items
Press on a dashed cell and drag to another to create a spanning item. Rename it, fine-tune its start and span, and switch on grid-template-areas. Or turn on Responsive columns instead.
Copy the code
Pick CSS, HTML, CSS + HTML or Tailwind and press Copy or Download. Copy share link saves the tracks, gaps and items in a URL.
Why CSS Grid Generator
- Its own size for every column and row, including fr, px, %, auto and minmax().
- Drag to place items, name them and output grid-template-areas or line numbers.
- Eight layout templates plus a responsive auto-fit mode.
- Alignment controls and CSS, HTML and Tailwind output that match each other.
fr vs px vs minmax vs auto: grid track sizes compared
Every column and row field takes any of these. Pick the unit by asking what should decide the size: the container, a fixed number, or the content.
| Track size | What decides the size | Good for |
|---|---|---|
| 1fr | A share of the space left after fixed tracks and gaps | Equal columns that fill the container |
| 200px | A fixed length | Sidebars, icon columns, fixed rows |
| auto | The content, stretched to fill spare space | Header and footer rows |
| minmax(0, 1fr) | Equal share that is allowed to shrink below content | Columns with long words or code |
| minmax(80px, auto) | At least 80px, taller if content needs it | Rows that must not collapse |
| 25% | A fraction of the container, gaps ignored | Rarely; fr is safer with gaps |
How grid line numbers place items
Grid items are placed by the lines between tracks, not by the tracks themselves. A grid with 4 columns has 5 vertical lines, numbered 1 to 5 from the left. grid-column: 1 / 5 therefore covers all four columns.
Worked example: set 4 columns and 3 rows, then drag across the whole top row, down the first column of rows 2 and 3, and across the other cells of rows 2 and 3. The output reads grid-column: 1 / 5 with grid-row: 1 / 2 for the header, grid-column: 1 / 2 with grid-row: 2 / 4 for the sidebar, and grid-column: 2 / 5 with grid-row: 2 / 4 for the main area. That is the classic header, sidebar and content layout in three short rules.
You can also write spans as grid-column: 1 / span 2, which reads as start at line 1 and cover two tracks. It produces the same result as 1 / 3.
Three grid layout templates to copy
These patterns cover most page and component layouts, and each one is a template button in the generator. Holy grail and Sidebar left load mixed track sizes with named areas, 12 columns loads twelve equal tracks, and the responsive card grid comes from the Responsive columns switch.
In each case the child elements stay plain divs in source order. Only the container rule and a few placement rules change, which is what makes grid layouts easy to rearrange at a breakpoint.
- Holy grail page: grid-template-columns: 200px 1fr 200px; grid-template-rows: auto 1fr auto; with the header and footer set to grid-column: 1 / 4.
- Sidebar and main: grid-template-columns: 240px 1fr; gap: 24px; the sidebar stays fixed and the main area takes the rest.
- Responsive card grid: grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; the browser fits as many 200px-plus columns as the width allows, with no media queries.
- 12-column system: grid-template-columns: repeat(12, 1fr); then place blocks with grid-column: span 4 or span 6.