Skip to content
🔳

CSS Grid Generator

Build a CSS grid layout visually and copy the code.

Runs in your browser

Updated

3
2
12px
12px

How the layout is assembled

Two sliders set columns (1 to 8, default 3) and rows (1 to 6, default 2), two more set the column and row gaps (0 to 60 pixels, default 12). A dropdown chooses the column template, two dropdowns choose justify-items and align-items, and a live preview between the controls and the code shows numbered cells repainting on every move.

A worked example

At the defaults the textarea emits display grid, grid-template-columns: 1fr 1fr 1fr, grid-template-rows: repeat(2, 1fr), gap: 12px 12px, and a @media (max-width: 640px) block that collapses the columns to 1fr; rows and gap are printed because rows are above one and at least one gap is nonzero. The gap line lists the row value before the column value, matching CSS syntax. With the template dropdown left at 1fr (equal), the declaration lists one 1fr track per column; the repeat() choice writes the same layout in shorthand, while minmax() writes repeat(3, minmax(0, 1fr)). Both stretch defaults are omitted from the output, and switching align-items to center adds just that one line.

What is and is not printed

Single-column output skips grid-template-rows entirely. When zero gaps, zero custom alignment and one row all hold at once, the rule shrinks to display and the columns line. The code always appends a .grid > * block carrying a #6366f1 background, white text, rounded corners and flex centring, which is preview styling you are meant to delete before shipping.

Where it stops

  • The Mobile Breakpoint option adds a block only when it differs from the current column count, and its 640px limit is fixed.
  • No auto-fill or auto-fit pattern is generated, so there is no card-wrapping layout from this page.
  • Areas, spans and named lines are out of reach; every cell is one grid square.
  • The class name is always .grid and cannot be changed.

Questions people ask

Why does minmax(0, 1fr) matter?

A bare 1fr track cannot shrink below the minimum content width of its children, which makes long words blow the column apart. The minmax variant is the standard fix, and that is why the dropdown offers it.

What do justify-items and align-items change?

They position each item inside its grid area. Both default to stretch, and neither line is printed unless you move it.

Pair the result with the flexbox generator for the inner alignment of each cell, tune the breakpoint behaviour in the media query generator, or convert the finished rule with css-to-tailwind.