CSS Grid Generator
Build a CSS Grid with 1–12 columns and rows, edit tracks and gaps, then select an item to set its lines and literal label.
Layout presets
Presets replace positions and labels; only Gallery and Cards change gaps.
Settings
One CSS track per field, such as auto, 1fr or minmax(200px, 1fr).
Preview
Select a block by pointer or keyboard to edit span and label.
Generated Code
Structural CSS and matching HTML; preview decoration is excluded.
Method and limits
Method and limits
fr shares remaining space after fixed tracks and gaps. The editor writes grid-template-columns, grid-template-rows, gap and alignment; custom positions use scoped child rules.
The preview is a sketch. Block colours, rounded corners and minimum heights are excluded from structural exports. Fixed tracks can overflow; add responsive rules at the destination. Incomplete tracks or invalid lines hide output without rewriting the draft.
The selected generator creates code from in-page fields. Copy requests clipboard access; refusal leaves selectable output. This describes editor logic, not other site requests or storage, which are not verified here.
Copied
Copy failed. Select the result and copy it manually.
About CSS Grid Generator
Build a CSS Grid with 1–12 columns and rows, edit tracks and gaps, then select an item to set its lines and literal label.
2 columns, 1 row, tracks 1fr and 2fr and both gaps 16px yield two items and gap: 16px 16px. The second track receives twice the flexible space, not necessarily two thirds of the full width.
CSS generator method; no dated external dataset. Test the destination integration.
Use Cases
How to use
Choose Holy Grail, Sidebar, Dashboard, Gallery, Blog or Cards, or keep the starting grid; presets replace positions and labels.
Set Columns and Rows from 1 to 12 and each gap from 0 to 64px.
Edit each track, for example 250px, auto, 1fr or minmax(200px, 1fr); complete the draft before copying.
Select a block and set start/end lines and label; justify-items and align-items align items within their grid areas.
Check the preview and errors, then copy CSS, HTML or both; use the stylesheet with its matching markup.
Pro Tips
- Dimension changes preserve custom spans of remaining items; correct out-of-range lines. A preset starts fresh.
- <b>Audit</b> stays text in preview and is escaped in HTML. Each field accepts one CSS track; unresolved custom properties are not evaluated.
- gap is printed as row gap then column gap, so gap: 16px 24px is 16 pixels between rows and 24 between columns; set them to the same number if the two-value form confuses reviewers.
Troubleshooting
The preview looks nothing like my page.
The preview is a sketch. Block colours, rounded corners and minimum heights are excluded from structural exports. Fixed tracks can overflow; add responsive rules at the destination. Incomplete tracks or invalid lines hide output without rewriting the draft.
Changing Columns reset my item spans.
Dimension changes preserve custom spans of remaining items; correct out-of-range lines. A preset starts fresh.
A preset wiped the track sizes I typed.
Presets set the columns, the rows, every track size and, for Gallery and Cards, the gaps as well. That is their purpose. Apply the preset you want as a starting point and edit afterwards; there is no undo, so copy the CSS out first if you want to keep it.
The gap looks wrong in one direction.
The shorthand prints row gap first and column gap second, so gap: 8px 24px puts 8 pixels between rows and 24 between columns. If that reads backwards to you, set Column Gap and Row Gap to the same value and the ambiguity disappears.
The copy buttons do nothing.
Copy failed. Select the output to copy manually.
Frequently Asked Questions
Select an item and set Col Start to 1 and Col End to 3. End lines are exclusive: lines 1–3 span two columns. The end must stay within columns + 1.
1fr shares remaining space; 1fr 2fr gives one and two shares after fixed tracks and gaps. Grid handles two axes; a grid item can contain Flexbox.
Set display: grid on the container, then describe the tracks with grid-template-columns and grid-template-rows and the spacing with gap. This page writes exactly that: the default produces .grid-container { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; gap: 16px 16px; } and the nine child divs that go with it.
A visual editor for the container properties. Instead of typing grid-template-columns and reloading to see the result, you set columns, rows, gaps and track sizes with fields, watch a live grid respond, and copy the finished rule. The output here is plain CSS with no framework and no class-name conventions to learn.
It is a fraction of the free space left after fixed tracks and gaps are subtracted. Three columns of 1fr each take a third of what remains; 1fr 2fr 1fr gives the middle column half. The Holy Grail preset mixes the two ideas — 200px 1fr 200px keeps the outer columns fixed and lets the middle absorb the rest.
With the Alignment block. justify-items: center centres each item horizontally inside its cell and align-items: center centres it vertically; justify-content and align-content move the whole grid inside the container when the tracks do not fill it. Set them here and the properties appear in the CSS only when they differ from stretch.
Historically it meant a framework's set of column classes, such as a twelve-column row you built pages out of. CSS Grid replaces that with a layout mode in the language itself, so instead of adding classes you declare the tracks. That is why the code this page produces has one container class and no column-count classes at all.
The style block goes in your stylesheet or a style element, and the divs go where the layout should appear. The Copy CSS and Copy HTML buttons split the two for you, while Copy All hands you the style block and the markup together, which is the fastest way to test it in a blank file.
Test the generated styles in the destination browser, page and input devices; this preview does not establish compatibility.