Skip to main content

Free CSS Grid Generator – Build Grid Layouts Visually

CSS Grid Generator builds CSS grid layouts visually and copies the code online for free. Set columns, rows, and gaps with a live preview in your browser.

Written & reviewed by Helperzy Editorial Team · Updated July 2026

Live PreviewCopy CSSColumns & Rowsfr UnitsFree

Live Preview

1
2
3
4
5
6

CSS

display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
gap: 8px;

100% Private

Everything runs locally in your browser. Nothing is uploaded.

How to Use CSS Grid Generator

1

Set Columns & Rows

Choose the track count and sizing. Use fr units for tracks that should share leftover space and fixed pixels only for elements like a sidebar that must not resize.

2

Adjust the Gap

Set the spacing between cells and watch the preview reflow. Gap never adds space at the outer edges, which is why it beats margins on the children.

3

Copy the CSS

Copy the declarations onto your container element. Avoid setting percentage widths on the children, since that fights the track sizing and causes overflow once gaps are counted.

How CSS Grid Tracks Work and How to Build a Layout

CSS Grid is the layout system for two dimensions at once. You define columns and rows on a container, and its children fall into the cells, which means a page structure that used to need nested wrappers and floats becomes two declarations. This generator lets you set the column count, the row count, the track sizes and the gap, with a live preview that reflows as you change each value, and it shows the exact CSS it produces. Front-end developers laying out a dashboard, anyone building a card gallery, and people who find the track-sizing syntax intimidating all get the same benefit: working code plus a readable example of the syntax. The core idea is the track. grid-template-columns lists the width of each column, and grid-template-rows does the same vertically, with each value in the list defining one track. The fr unit is what makes grid flexible: it means one fraction of the leftover space after fixed sizes and gaps are subtracted, so 1fr 1fr 1fr gives three equal columns that resize with the container. The repeat function shortens that to repeat(3, 1fr). gap sets the space between tracks, and unlike the old margin approach it never adds space at the outer edges. Two functions do the heavy lifting for responsive work: minmax sets a floor and ceiling for a track, and auto-fit combined with minmax lets the browser decide how many columns fit, which produces a responsive gallery with no media queries at all. Do the arithmetic on a real container. Suppose your grid is 960 pixels wide with grid-template-columns set to repeat(3, 1fr) and a gap of 24 pixels. Two gaps sit between the three columns, consuming 48 pixels, leaving 912 pixels of free space that the three fr tracks split equally at 304 pixels each. Change the declaration to repeat(auto-fit, minmax(240px, 1fr)) and the browser instead works out how many 240-pixel-minimum columns will fit: at 960 pixels wide it lands on three columns of 304 pixels, at 560 pixels it drops to two, and below 504 pixels it falls to a single full-width column. Same one line of CSS, fully responsive, with no breakpoints written by hand anywhere. Where this gets used. A developer builds an admin dashboard with a fixed 240-pixel sidebar and a flexible main area using grid-template-columns 240px 1fr. A photographer lays out an image gallery with auto-fit and minmax so it reflows from three columns to one without a single media query. Someone building a pricing page arranges three cards of equal height, since grid rows stretch to match by default. A team creating a form places labels and inputs in two aligned columns, which grid handles cleanly because alignment happens across rows as well as within them. A developer builds a magazine layout where one feature card spans two columns and three rows. Two points worth internalising. Grid and flexbox are not competitors: flexbox handles a single row or column of content, grid handles both directions at once, and most real pages use grid for the page skeleton and flexbox inside individual components. Reaching for grid to lay out a navbar is overkill; reaching for flexbox to lay out a dashboard means nested containers and fighting alignment. The pitfall beginners hit is putting a percentage width on grid children, which fights the track sizing and causes overflow once the gap is added; let the tracks control width and leave the children at their natural size. Grid needs no prefixes in any current browser, so the generated declarations can ship exactly as they appear. Everything runs in your browser and nothing is uploaded anywhere.

Examples: CSS Grid Generator

Input

3 equal columns, 24px gap, container 960px wide

Result

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; } — each column renders 304px

Two 24px gaps consume 48px, leaving 912px of free space that the three fr tracks divide equally, giving 304px per column.

Input

Responsive gallery: minimum column width 240px, 24px gap

Result

.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; }

auto-fit lets the browser count how many 240px-minimum tracks fit, so the same line gives three columns at 960px, two at 560px and one below 504px with no media queries.

Frequently Asked Questions – CSS Grid Generator

Set the number of columns and rows, their sizes, and the gap in the Helperzy CSS Grid Generator. A live preview updates instantly, and you can copy the generated grid CSS, including grid-template-columns and rows, into your project.