CSS Grid Generator

Design a grid the way you think about it — columns, rows and a gap — see it rendered live with numbered cells, and walk away with the exact CSS and matching HTML.

1Set columns, rows and gap
2Check the live grid preview
3Copy the CSS and HTML

Your CSS

Matching HTML

Private by design: 100% in your browser — nothing is uploaded, no sign-up. This tool runs entirely on your device.

How to use this CSS grid generator

Three sliders are the whole interface. Columns and rows set how many tracks your layout has in each direction, and the gap slider sets the breathing room between cells. The preview beneath rebuilds itself on every movement, filled with numbered cells so you can see exactly where each item will land — cell 1 top-left, flowing across the first row, wrapping onto the next. The two code blocks update in step: the CSS declaration for your container, and the matching HTML skeleton with the right number of child divs, so you can copy both and have a working grid before you have written a word of your own markup.

The columns in the generated code use the fr unit — repeat(3, 1fr) — which divides the container's width into equal shares after the gaps are subtracted. That is the behavior most layouts actually want: cards that stretch to fill the row and stay equal no matter the screen. If your real design needs a fixed sidebar beside fluid content, generate the grid here first, then edit one track by hand — grid-template-columns: 260px 1fr is the classic. Learning grid by editing working output beats staring at a blank stylesheet, which is the entire philosophy of this tool.

Rows deserve one honest note. The generated grid-template-rows: repeat(2, 1fr) sizes rows as equal fractions of the container's height, which the preview shows because its stage has a fixed height. In a real page, containers usually grow with content; many developers drop the rows line entirely and let rows size themselves, keeping only the columns and gap. Both are correct — the generator shows the full form so you can see what each line does, and deleting a line you do not need is easier than inventing one you do.

Example: a 3 × 2 card grid with 16px gaps

The default settings on this page generate exactly this:

.grid-container { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 16px; }

Four declarations, one layout. display: grid turns the container into a grid context; the two template lines declare three equal columns and two equal rows — six cells, like the preview; and gap promises 16 pixels between every pair of tracks, with no stray margins at the edges. The HTML block gives you the container with six child divs to match. Replace the numbers with your content, style the children, and a card wall that once took an evening of float-wrangling is done in minutes — and it will wrap gracefully when you add a seventh card, because the grid simply grows a new row.

Why grid won the layout wars

For twenty years, page layout was CSS's missing feature, faked with tables, then floats, then frameworks of twelve-column classes and clearfix hacks. Grid ended the improvisation by making the browser itself responsible for two-dimensional placement: you describe the structure once, and alignment, equal heights and even spacing stop being per-element chores. The practical consequences are enormous — a gallery needs no height matching, a dashboard reflows by changing one template line, and source order can finally match reading order instead of visual hacks. If you learn one modern layout tool, this is the one; flexbox remains its perfect partner for one-dimensional rows inside the cells grid creates.

Making the generated grid responsive

A fixed three-column grid is a desktop answer. The standard responsive upgrade keeps this generator's structure and changes one line: grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)). Now the browser itself decides the column count — as many minimum-220-pixel columns as fit — collapsing to two, then one, as the screen narrows, with no media queries at all. Use the generator to find the shape and gap that flatter your content at full width, note the minimum width at which a cell still looks good, and put that number in minmax(). For layouts where the structure itself changes — a sidebar that becomes a top bar — media queries that swap between two generated templates are cleaner than cleverness. Generate both shapes here, paste both into your stylesheet, and let the breakpoint choose.

Frequently asked questions

What is CSS Grid?

CSS Grid is the browser's built-in two-dimensional layout system. You declare a container as a grid, define how many columns and rows it has and how wide the gaps between them are, and the browser places your items into the cells. It handles in a few lines what used to take floats, clearfixes and nested wrapper divs.

What does repeat(3, 1fr) mean?

It means: create 3 tracks, each one fraction (1fr) of the available space. The fr unit divides whatever room is left after fixed sizes and gaps, so three 1fr columns are always equal thirds. repeat() simply saves you typing the same size over and over.

Grid or Flexbox — which should I use?

Grid lays out in two dimensions — rows and columns at once — which makes it the right tool for page layouts, galleries, dashboards and card walls. Flexbox is one-dimensional, perfect for a row of buttons, a nav bar or centering content. Most real pages use both: grid for the overall structure, flexbox inside the components.

What does the gap property do?

gap sets the space between tracks — between columns, rows, or both with one value. Unlike margins, gap never adds space at the outer edges and never collapses, which is why grid layouts stay perfectly even. This generator applies one gap value to both directions, the most common setup.

How do I make the grid responsive?

The classic responsive pattern replaces a fixed column count with repeat(auto-fit, minmax(220px, 1fr)): the browser fits as many columns of at least 220px as the width allows and wraps the rest. Use this generator to prototype the shape you want, then swap the template line for the auto-fit version in your stylesheet.

Can grid items span multiple columns or rows?

Yes. An item with grid-column: span 2 occupies two columns; grid-row: span 2 occupies two rows. Spanning is how hero cards, featured images and dashboard widgets break the uniform rhythm on purpose. The generator builds the uniform base grid; add span rules to individual items afterwards.

What if I have more items than cells?

The grid simply grows. Extra items flow into new rows that the browser creates automatically — the implicit grid. Your column definition still applies, so a photo wall with a 4-column template handles 9 photos or 900 with the same CSS.

Do all browsers support CSS Grid?

Yes. Grid has been supported in every major browser since 2017, including on mobile. The properties this generator outputs — display: grid, grid-template-columns, grid-template-rows and gap — are among the safest modern CSS you can ship.

Is anything I create uploaded or tracked?

No. The preview and the code are generated by JavaScript in your own browser. Settings you choose are never sent to a server or stored anywhere — closing the tab clears everything.

Related tools