Search tools

CSS Grid Generator

Set columns, rows and gaps, drag to place items across cells, and copy matching CSS and HTML.

CSS Grid Generator tool

Sizes accept any CSS track: 1fr, 200px, auto, minmax(120px, 1fr). Changing the column or row count resets these to equal sizes.

Preview — drag across empty cells to create an item that spans them

Processing runs in your browser.

CSS grid is the most powerful layout tool in CSS, but its syntax is dense. Track lists, line numbers and spans are hard to picture from code alone. This generator lets you build the layout on a visual board first, then gives you code you can paste straight into a project.

A quick example

Click Example layout. You get a four-column, three-row grid with a header across the top, a 200px sidebar, a wide main area and a footer. The code looks like this:

grid-template-columns: 200px 1fr 1fr 1fr;
grid-template-rows: auto 1fr auto;

Each item gets a grid-column and grid-row with a span, so you can see exactly where it sits.

Choosing track sizes

  • fr shares out the free space. Ideal for flexible content areas.
  • px or rem gives a fixed size, such as a sidebar or icon column.
  • auto sizes to the content, which suits headers and footers.
  • minmax(150px, 1fr) sets a lower limit so columns never get too narrow.

Tips

  • Gaps only appear between tracks, not around the outside. Add padding to the container for an outer margin.
  • Items you don’t place are flowed into empty cells automatically, in source order.
  • Keep the HTML order logical for screen readers and keyboard users. Grid can move things visually, but assistive technology still follows the source.

How to use the CSS Grid Generator

  1. Choose how many columns and rows you need, and set the column and row gaps.
  2. Edit the Column sizes and Row sizes fields with any CSS track, such as 200px 1fr.
  3. Drag across empty cells in the preview to create an item that spans them.
  4. Rename items in the list below the preview to match your class names.
  5. Copy the CSS and the HTML, or click Example layout to see a classic page layout.

Features

  • Up to 12 columns and 10 rows, with separate column and row gaps.
  • Track sizes in fr, px, rem, %, auto, min-content, minmax() and fit-content().
  • Drag-to-place items with column and row spans, overlap prevented.
  • Output uses repeat() when tracks are equal.
  • Generates both the container CSS and the matching HTML.

Frequently asked questions

What does 1fr mean in CSS grid?

fr means a fraction of the free space. Three columns of 1fr share the width equally; 2fr 1fr gives the first column twice the space of the second. Fixed sizes like 200px are taken out first.

When should I use grid instead of flexbox?

Use grid when you care about rows and columns at the same time, such as page layouts, galleries and dashboards. Use flexbox for one-direction lines of items, such as toolbars, navigation or a row of buttons.

How do I make a responsive grid without media queries?

Use repeat(auto-fill, minmax(200px, 1fr)) for the columns. The browser fits as many 200px-or-wider columns as the screen allows and wraps the rest onto new rows.

What does grid-column: 1 / span 3 mean?

The item starts at the first column line and stretches across three columns. The generator writes items this way, which is easy to read and to adjust later.

Written by