🔒 100% private — runs in your browser, nothing is uploaded

CSS Grid Generator

Lay out a two-dimensional grid visually — columns, rows and gap — and copy the container CSS with repeat() and fr tracks.

CSS grid is the two-dimensional layout system: you define rows and columns on a container, and items place themselves into the tracks. The declaration this generator produces is the workhorse form — display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 16px. Read it as: make a grid, split the width into 3 equal columns and the height into 2 equal rows, and leave 16px gutters between tracks. The unit doing the equal split is fr, the fraction unit: 1fr means one share of the space left after fixed tracks and gaps are subtracted, so repeat(3, 1fr) is always three identical columns at any container width — no percentage arithmetic and no rounding gaps. The worked example is the classic photo gallery: a container with those three lines of CSS and six image divs inside renders a tidy 3 × 2 gallery that stretches and shrinks with the viewport.


Everything runs in your browser; your values are never uploaded, stored or put into a link. The CSS targets the grid container; the items inside place themselves automatically, row by row.

Quick answers

How do I make a 3-column gallery with CSS grid?

On the container: display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px. The children flow three per row automatically — no widths or floats on the items themselves.

Add grid-template-rows only if you need fixed row heights; otherwise rows size to the tallest item in each row.

How is CSS grid different from flexbox?

Grid is two-dimensional (you control rows and columns together); flexbox is one-dimensional (a single row or column whose items size to content). Galleries and page layouts are grid’s home ground; nav bars and toolbars are flexbox’s.

They compose: a grid cell can contain a flex row, and a flex item can be a grid. Most production layouts use both.

How to use

  1. Set the number of columns and rows — the generator writes them as repeat(n, 1fr), so every track gets an equal share of the space.
  2. Set the gap in px; one value spaces both the column and row gutters evenly.
  3. Change the preview item count to see how items flow into the tracks and wrap onto implicit rows when they overflow.
  4. Copy the generated CSS onto your container element; the items inside need no classes of their own for this basic layout.

About this tool

Grid’s partner is flexbox, and the division of labour is simple: grid arranges in two dimensions at once (rows and columns of a page region or a gallery), flexbox arranges in one dimension (a row of nav items, a column of form fields) — the CSS Flexbox Generator on this site covers that side. Items beyond the explicit rows are not an error: they flow into implicit rows sized by their content, which is why a 3-column grid with 7 items simply grows a third row. When you outgrow equal tracks, the same properties accept explicit lists instead of repeat() — grid-template-columns: 200px 1fr 2fr mixes a fixed sidebar with proportional tracks, and minmax() with auto-fill is the usual next step for card galleries that should add or drop columns as space allows. Those are hand-written refinements; the repeat() form here is the correct starting point and stays valid underneath them.

Frequently asked questions

What does 1fr mean in CSS grid?

One fraction of the available space. After fixed-size tracks (px, %) and gaps are taken out, the remaining space is divided among fr tracks in proportion: 1fr 2fr gives the second track twice the first. repeat(3, 1fr) therefore always produces three equal columns at any width.

What does repeat() do in grid-template-columns?

It writes a repeating track pattern without typing it out: repeat(3, 1fr) is exactly grid-template-columns: 1fr 1fr 1fr. It also accepts patterns, such as repeat(2, 1fr 2fr), and the auto-fill / auto-fit keywords used for responsive card galleries.

Should I use grid or flexbox for this layout?

Grid when the layout is two-dimensional — galleries, dashboards, page regions where rows and columns must align with each other. Flexbox when it is one-dimensional — a toolbar, a nav bar, a row of chips — where items should size to their content and distribute along a single line. Real pages use both, nested.

How do I make the grid responsive?

Three common steps up from this fixed form: swap repeat(3, 1fr) for repeat(auto-fill, minmax(220px, 1fr)) so columns appear and disappear with width; change the column count inside media queries at your breakpoints; or drop grid-template-rows entirely and let rows size to content. The equal-track generator output is the right base for all three.

📦 Embed this tool on your site

<iframe src="https://verystep.com/embed/css-grid-generator/" title="CSS Grid Generator" width="100%" height="520" loading="lazy" style="border:0"></iframe>

Free to use. The embed shows a small "Powered by Verystep" link.

First time embedding? Read the step-by-step guide →

More free tools