W3docs

Tools

CSS Grid Generator

Define columns, rows and gaps, place items across lines, watch the grid update live, and copy the CSS and HTML. Track lists are kept exactly as you write them.

CSS grid generator

Runs entirely in your browser. Nothing you type is sent to a server.

Presets:
Container
learn
learn

Tracks take fr, px, %, auto, minmax(), fit-content() and repeat(), including repeat(auto-fill, …).

learn
learn
learn
learn
learn
learn
learn
Items

1 to 100 items. Click an item in the preview or below to edit it.

Item 1

learn
learn
learn

Preview

Drag the bottom-right corner to resize

CSS

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

HTML · 6 items

<div class="container">
  <div class="item item-1">1</div>
  <div class="item item-2">2</div>
  <div class="item item-3">3</div>
  <div class="item item-4">4</div>
  <div class="item item-5">5</div>
  <div class="item item-6">6</div>
</div>

About the CSS grid generator

CSS grid places items in rows and columns at the same time. You describe the tracks with grid-template-columns and grid-template-rows, the gaps between them, and, where you need it, which lines an item starts and ends on. This generator gives each of those a control and redraws the grid as you type.

Track lists accept everything grid itself does for sizes: fr, px, %, auto, min-content, max-content, minmax(), fit-content(), repeat() with a count, and repeat(auto-fill, …) or repeat(auto-fit, …) for responsive grids. What you type is kept as written, so repeat(3, 1fr) stays repeat(3, 1fr). The column and row count fields rewrite the list for you.

Anything that is not valid grid syntax is left out of the CSS and explained next to the field, and a value can never break out of its declaration. Everything runs in your browser; nothing you type is sent anywhere.

Worked example: a featured tile

Four equal columns, two fixed rows, and a first item that covers a two-by-two block. Only item 1 needs its own rule.

Item 1 spans two columns and two rowscss
.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 100px);
  gap: 10px;
}

.item-1 {
  grid-column: span 2;
  grid-row: span 2;
}
Responsive cards without media queriescss
.container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

auto-fill creates as many 120px-or-wider columns as fit; resize the preview to watch the column count change.

Frequently asked questions

What does 1fr mean?

fr is a share of the free space in the grid container. 1fr 2fr gives the second column twice the leftover space of the first, after fixed tracks and gaps are taken out.

What is the difference between auto-fill and auto-fit?

Both create as many tracks as fit. With auto-fill empty tracks keep their space; with auto-fit empty tracks collapse, so the filled ones stretch across the whole row.

How do I make an item span several columns?

Set grid-column on that item: 1 / 3 runs from line 1 to line 3, span 2 covers two columns from wherever the item lands, and 1 / -1 stretches across the whole explicit grid.

Why does gap take two values?

The first value is the gap between rows and the second the gap between columns. This tool has a separate field for each, so the order can never get swapped.

Is there a limit on tracks or items?

Up to 50 explicit tracks per axis and 100 items. Larger values are refused with a message, and the output keeps the last valid layout.