
CSS Grid Generator
Build CSS Grid layouts visually. Adjust columns, rows, and gaps - then copy the generated CSS.
Last reviewed: June 2026New to this tool? Click here for instructions
Click a cell to toggle column span. Blue = spanned.
How the CSS Grid Generator works
The generator is a local CSS builder. Slider changes, template edits, mode switches, gap controls, and clicked preview cells are translated into CSS Grid declarations in the page's own JavaScript. There is no backend request for layout generation; the preview and output update from the current browser state.
Use explicit grid mode when you know the exact number of tracks. Use auto-fill or auto-fit when the grid should adapt to available width. Use named lines when the generated CSS needs semantic placement hooks such as [sidebar-start], [content-start], and [content-end].
Practical layout guidance
- Use
frfor flexible space:1fr 2frgives the second track twice the leftover width of the first. - Use
minmax()for responsive cards:repeat(auto-fit, minmax(16rem, 1fr))avoids fragile breakpoint-only layouts. - Use gaps instead of margins:
gapkeeps spacing tied to the grid container and reduces child-specific overrides. - Validate spans: a preview span that looks good with placeholder cells may still need content-length testing in the real component.
Worked example
For a product-card gallery, choose auto-fit mode, set the minimum column size around 16rem, and use a 16-24 px gap. The generated grid-template-columns pattern lets the layout collapse from four columns to one without a custom media query.
Sources
Frequently Asked Questions
Grid output checklist
| Decision | Use when | Example |
|---|---|---|
| Explicit tracks | The layout always needs a fixed track count. | grid-template-columns: 240px 1fr; |
| Auto-fit cards | Cards should stretch to fill each row. | repeat(auto-fit, minmax(16rem, 1fr)) |
| Auto-fill cards | Empty tracks should remain reserved. | repeat(auto-fill, minmax(12rem, 1fr)) |
| Named lines | Placement should be readable in code review. | [nav] 12rem [main] 1fr |