CSS grid generator

A CSS grid generator writes display: grid code for you. Set the columns, rows and gaps, for example grid-template-columns: repeat(3, 1fr); gap: 16px, preview the layout and copy the CSS or Tailwind classes.

Set the number of columns and rows, the gaps between them and how each track is sized. The preview updates as you type, and the CSS and Tailwind classes are ready to copy.

1
2
3
4
5
6

CSS

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

Tailwind classes

grid grid-cols-3 grid-rows-2 gap-[16px]

How to use it

  1. Choose how many columns and rows you need (1 to 12 each) and pick fr, auto or minmax sizing for each direction.
  2. Set the column gap and row gap in pixels and watch the numbered cells in the preview move as you type.
  3. Copy the CSS rule for your stylesheet, or the Tailwind classes for your markup.

Want to see grids in real products? Browse the website section examples and the landing page examples for feature grids, pricing tables and card galleries you can rebuild with this tool.

When the grid should change at a different screen width, use the CSS media query generator to write the matching min-width, max-width or range query and copy it with the grid CSS.

Frequently asked questions

What is grid-template-columns?

grid-template-columns defines how many columns a grid container has and how wide each one is. repeat(3, 1fr) creates three equal columns, while a list like 200px 1fr gives a fixed sidebar next to a flexible main area. Children then fill the cells in order unless you place them with grid-column.

What is the difference between fr, auto and minmax(0, 1fr)?

1fr gives each track an equal share of the free space, but its minimum is the content's minimum width, so a long word or wide image can push a column wider than the others. auto sizes the track to its content and lets it stretch to fill leftover space. minmax(0, 1fr) lets a track shrink to zero, so columns stay truly equal even with long content; it is what Tailwind's grid-cols-N classes use.

What is the difference between gap, column-gap and row-gap?

column-gap sets the space between columns and row-gap sets the space between rows. gap is the shorthand for both: one value applies to both directions, and two values are read as row gap first, then column gap. Gaps only add space between tracks, never around the outside edge of the grid.

Should I use CSS grid or flexbox?

Use grid when you are laying out in two directions at once, such as a card gallery, a dashboard or a page with header, sidebar and content areas. Use flexbox for one-direction layouts like a nav bar, a row of buttons or items that should wrap based on their own size. Many layouts use both: grid for the page structure and flexbox inside each cell.

More CSS generators

Color tools

Image tools

Image & SVG tools

Typography & units

More free tools

All free tools