CSS grid generator

Set how many columns and rows you need, give each track a size, add gaps and let chosen items span several cells. The preview follows every change and you get matching HTML and CSS to copy.

Columns
1
2
3
Rows
1
2

CSS

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

HTML

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

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Set the number of columns and rows. Each one gets a size row below.
  2. Choose a size type per track: fr for flexible shares, px for a fixed size, auto to fit the content, or minmax for a minimum in pixels that can still grow.
  3. Set the column and row gaps.
  4. Set the number of items. To make one larger, select it and raise its spans.
  5. Copy the CSS and the HTML.

What the output means

The .grid rule has display: grid, the two template lines and a gap. When the gaps differ, the shorthand is written row first, then column: gap: 8px 16px. Items with a span get their own .item-N rule; other items need no rule, because the browser places them in order.

Example

Three equal columns and two auto rows with a 16px gap give grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, auto); gap: 16px;. Setting item 2 to span two columns adds .item-2 { grid-column: span 2; }.

Tips

  • Use minmax() columns for cards that should wrap into fewer columns on small screens, together with repeat(auto-fit, ...) written by hand.
  • Items placed by spans can leave holes. Add grid-auto-flow: dense yourself if you want the browser to fill them.
  • This tool does not draw named areas; for those, write grid-template-areas on top of the generated rule.

Frequently asked questions

What is the fr unit?

One fr is a share of the free space in the grid container. With columns of 1fr 2fr the second column is twice as wide as the first, after any fixed sizes and gaps are subtracted.

What does minmax(200px, 1fr) mean?

The track is never narrower than 200px, and grows to take its share of free space when there is room. In this tool the minmax option always uses 1fr as the maximum and the number you enter in pixels as the minimum.

How do I make an item span several cells?

Pick the item in Selected item and raise its column span or row span. The CSS gets a rule such as .item-2 { grid-column: span 2; } for that item. Spans are limited to the number of columns and rows you have.

Why is the output written with repeat()?

When all columns, or all rows, have the same size, the tool writes repeat(3, 1fr) instead of 1fr 1fr 1fr, which is shorter and easier to change. Tracks with different sizes are listed one by one.

More in Color

All tools in this category: Color ·Updated November 3, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.