CSS Grid Generator

Set your columns and rows, adjust the gaps, and watch the grid build itself. Track sizes cover fr units, fixed pixels, auto, min-content, max-content and minmax, or type your own. Identical tracks collapse into repeat() in the output, because repeat(12, 1fr) is what you would write and a twelve-item list is not something anyone wants to maintain. Switch on auto-fit for the most useful pattern in grid and the least well known: repeat(auto-fit, minmax(200px, 1fr)) fits as many columns as will hold 200px and stretches them to fill the row — a fully responsive grid with no media queries at all.

Track sizes

ValueMeaning
1frAn equal share of the remaining space
200pxFixed, never changes
autoAs large as its content needs
min-contentAs narrow as possible without overflowing
max-contentAs wide as the content wants
minmax(200px, 1fr)At least 200px, otherwise an equal share

When to use it

  1. Lay out a page with a sidebar and a main column.
  2. Build a responsive card grid without media queries.
  3. Create a twelve-column layout with consistent gutters.
  4. Work out what minmax actually does to a track.
  5. Get the grid-template CSS without writing it by hand.

How to Use

  1. Add or remove column and row tracks and pick their sizes.
  2. Adjust the row and column gaps.
  3. Switch on auto-fit for a responsive grid, then copy the CSS.

Features

  1. Per-track sizing including minmax and content keywords
  2. Separate row and column gaps
  3. Responsive auto-fit columns with an adjustable minimum
  4. Identical tracks collapsed into repeat()
  5. Live preview that matches the output exactly
  6. Runs entirely in your browser

FAQs

What is an fr unit?

A fraction of the space left after fixed-size tracks are placed. 1fr 2fr gives the second track twice the leftover space. Unlike percentages, fr accounts for gaps automatically, which is why three 1fr columns with a gap fit exactly where three 33.33% columns overflow.

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

They behave identically until the grid is sparsely filled. auto-fill keeps the empty tracks, so three cards in a container with room for six sit in the left half with empty space beside them. auto-fit collapses the empty tracks, letting the three cards stretch across the full width. auto-fit is usually what people want.

What does minmax do?

Sets a floor and a ceiling for a track. minmax(200px, 1fr) means never narrower than 200px, otherwise take an equal share of the space. Combined with auto-fit it produces a responsive grid in a single declaration.

When should I use grid instead of flexbox?

When you care about both dimensions. Grid aligns things into rows and columns simultaneously, so a card grid keeps its columns lined up regardless of content height. Flexbox handles one dimension at a time and is better for a row of buttons or a navigation bar.

Why do I not need to define rows?

Because grid creates implicit rows for any content beyond your explicit tracks, sized by their content. Defining rows explicitly only matters when you need specific heights or are placing items into named areas.

Why does the output use repeat()?

Because it is what you would write. repeat(3, 1fr) and 1fr 1fr 1fr are identical to the browser, but one is readable at twelve columns and the other is not.

Technical Details

Identical tracks are collapsed into repeat() rather than listed out, because repeat(12, 1fr) is what a person writes and a twelve-item list of 1fr is unreadable in a stylesheet someone has to maintain. Gaps collapse too: one value when the row and column gaps match, two when they differ, and nothing at all when both are zero. The auto-fit mode replaces the column list entirely rather than sitting alongside it, since repeat(auto-fit, minmax(…, 1fr)) is a complete specification of the columns and a fixed track list would contradict it. That pattern is the most useful thing in CSS grid and the least well known: it fits as many columns as will hold the minimum width and stretches them to fill the row, giving a fully responsive grid with no media queries. The distinction from auto-fill is worth stating, because they look identical until the grid is sparsely populated — auto-fill keeps the empty tracks, so three cards in a container with room for six sit in the left half with a gap beside them, while auto-fit collapses the empties and lets the cards stretch. An empty track size falls back to 1fr rather than emitting nothing, which would produce a grid-template-columns declaration with a missing value and invalidate the whole rule.

Web & CSS Tools

Web & CSS Tools

  • CSS Border Radius Generator
  • CSS Box Shadow Generator
  • Cubic Bezier Generator
  • CSS Clip Path Generator
  • CSS Keyframes Generator
  • CSS Unit Converter
  • Layout Grid Calculator
  • Design Tokens Converter