What Is CSS Grid?
CSS Grid is the most powerful layout system in CSS — it handles two-dimensional layouts with precise control over rows, columns, gaps, alignment, and item placement. Before Grid, complex page layouts required floats, tables, or framework-specific classes. Grid makes them achievable with pure CSS.
Key Grid Concepts
grid-template-columns / rows — defines the track sizing. Use px, %, fr (fraction), minmax(), or auto. gap — spacing between grid cells (replaces the old grid-gap). grid-column / grid-row — places items across specific tracks using line numbers or span. fr unit — distributes available space proportionally, like flex-grow for grids.
How to Use This Grid Generator
- Set the number of columns and rows — Define your grid dimensions — common layouts include 12-column grids for full pages and 2–4 column grids for content sections.
- Adjust column and row sizes — Set sizes using fr units (fractional), px, %, auto, or minmax() for responsive behavior.
- Set gap spacing — Control the gap between rows and columns independently.
- Check the preview — Each cell shows where items will land with the current tracks, gap and alignment. Spanning items across tracks is done in your own CSS (grid-column / grid-row on the children); the tool generates the container rules.
- Copy the CSS — Grab the complete grid-template-columns, grid-template-rows, and gap declarations.
Worked example: the presets at desktop and phone width
On October 12, 2026 we applied each preset's copied CSS to a container in Chromium and read the computed column widths (getComputedStyle().gridTemplateColumns) at 960 px and at 358 px, the content width of a 390 px phone with 16 px padding each side.
| Preset | Copied columns | 960 px container | 358 px container |
|---|---|---|---|
| 2-Col | 1fr 1fr, gap 16 | 472 / 472 | 171 / 171 |
| 3-Col | 1fr 1fr 1fr, gap 16 | 309 × 3 | 109 × 3 |
| Sidebar | 250px 1fr, gap 0 | 250 / 710 | 250 / 108 |
| Holy Grail | 200px 1fr 200px, gap 0 | 200 / 560 / 200 | 200 / 0 / 200 (42 px overflow) |
| Magazine | 2fr 1fr, gap 16 | 629 / 315 | 228 / 114 |
| Gallery | 4 × 1fr, gap 8 | 234 × 4 | 84 × 4 |
| Card Grid | repeat(3, 1fr), gap 20 | 307 × 3 | 106 × 3 |
- Fixed tracks win, fr tracks get what is left. A
1frtrack is only the space remaining after px tracks and gaps. Holy Grail's two 200 px sidebars leave nothing for the content column on a phone and push 42 px past the container; Sidebar leaves 108 px. Wrap fixed sidebars in a media query, or useminmax(0, 250px)/clamp()widths. - Use
minmax(0, 1fr)when content can be wide. Plain1frhas an automatic minimum of the content's min-content width, so a long URL or a wide image stretches its column past an equal share.minmax(0, 1fr)lets the column shrink and keeps columns equal. - For a responsive card grid, swap the fixed count for auto-fit.
repeat(auto-fit, minmax(240px, 1fr))gives 3 columns at 960 px and 1 at 358 px with no media query. Type it into the column editor and the preview shows the columns the browser actually builds at the current width. - What the tool outputs. The copied CSS is the container only:
display,grid-template-columns,grid-template-rows,gap(or separate row/column gaps), plusjustify-items/align-itemswhen not stretch. It does not place or span items; addgrid-column: span 2to children yourself. - The preview counts the tracks the browser builds. Until October 13, 2026 it drew one cell per track you typed, so repeat(3, 1fr) counted as one and the Card Grid preset showed 1 cell instead of 3. It now lays the same template out on an empty probe and reads the resolved track list (getComputedStyle expands repeat(), auto-fill and minmax() into one size per track), then draws columns × rows cells. In Chromium all 8 presets matched at 1280 and 390 px wide (Card Grid: 3 cells), and repeat(auto-fill, minmax(150px, 1fr)) gave 5 columns in the 932 px preview and 2 on a phone. A value the browser rejects (for example 12qq) is flagged under the CSS output.
Sources
Checked on .
Frequently Asked Questions
📖 Learn More
Related Article CSS Flexbox vs Grid: When to Use Which → Related Article How to Use CSS Grid Layout →Built by Derek Giordano · Part of Ultimate Design Tools