← All tools/Generators/Design/CSS Grid Generator

CSS Grid Generator

Lay out columns, rows and gaps, watch the grid change live, then copy clean CSS Grid code.

px
px

Live preview

6 cells

3 columns × 2 rows · 16px gap

.grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 16px; }
Grid size3 × 2
Total cells6
Gap16px × 16px

How it works

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

3 equal columns, 2 rows and a 16px gap give a 3 × 2 layout with 6 equal cells. repeat(3, 1fr) means three tracks that share the space equally; change 1fr to 120px for fixed-width columns.

CSS Grid track syntax per the CSS Grid Layout specification (W3C): repeat() builds identical tracks, fr units share free space. Last updated November 2026.

Frequently asked questions

What does 1fr mean?

One fraction of the free space. repeat(3, 1fr) splits the container into three equal columns; 2fr 1fr would make the first column twice as wide as the second.

What is the difference between gap and padding?

Gap is the space between grid cells; padding is the space inside the container’s edges. This generator sets gap only, so the cells sit flush with the container.

Can I use pixels instead of fr?

Yes — pick 120px for fixed columns, or auto to size each track to its content. Fixed tracks do not stretch, so they can overflow a narrow screen.

How do I place an item across two columns?

On the child, use grid-column: span 2 (or grid-column: 1 / 3). The container CSS this tool generates stays the same.

More tools

Tell us what you think

Loving this tool, or stuck on something? Tell us — it takes a minute.

We’ll only use your name and email to reply if needed. The tool and page are filled in for you.