CSS Grid Generator

Build CSS Grid layouts visually. Set columns, rows, gaps, and template values with live preview and instant code output. Free, browser-based.

  • Runs in your browser
  • Your data never leaves your browser
  • Free · No Sign-Up
Set 1–12 columns. Changing the count rebuilds the cells and replaces the column template with repeat(N, 1fr).
Set 1–8 rows. Changing the count rebuilds the cells and replaces the row template with repeat(N, 1fr).
Enter a CSS length such as 24px, 1.5rem or 2%. An empty field uses 1rem; typed values are copied without validation.
Set the row spacing. The preview gap writes the row gap before the column gap. An empty field uses 1rem.
Custom templates
Enter a custom column template after setting the count. Gap changes retain it; changing Columns replaces it. The preview always contains Columns × Rows cells.
Enter a custom row template after setting the count. Gap changes retain it; changing Rows replaces it. Templates are copied as typed.
Copy the complete .container rule with its five declarations. Ctrl/⌘+L clears text, CSS and preview while keeping counts. Retry a failed copy or select the CSS manually.

Read the full guide CSS Grid Explained: Tracks, fr, Named Areas, auto-fill vs auto-fit and Subgrid
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.

Understanding the Generated CSS

The generator outputs a single .container rule with five properties: display: grid, grid-template-columns, grid-template-rows, column-gap, and row-gap. Paste it into your stylesheet and rename .container to match your own class name. The rule describes the container only; the children are placed automatically, one per cell, in source order.

Example: the Default 3 × 2 Grid

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  column-gap: 1rem;
  row-gap: 1rem;
}

In a 1000px-wide container with a 16px root font size, Chrome resolved the columns to 322.664px each: (1000 − 2 × 16) ÷ 3. The rows behave less obviously. When the container has no fixed height, 1fr rows are sized from their content and then equalized, so one 200px-tall item made both rows 200px tall. With repeat(2, auto) the same items gave rows of 20px and 200px. Use auto rows unless you want every row to match the tallest one.

Example: Sidebar and Main Area

Set Columns to 2 and Rows to 3, type 240px 1fr into grid-template-columns and auto 1fr auto into grid-template-rows, then set the column gap to 24px and the row gap to 0:

.container {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr auto;
  column-gap: 24px;
  row-gap: 0;
}

At 960px wide, the main column measured 696px (960 − 240 − 24). The middle row takes whatever height is left once the container has a height, for example min-height: 100vh, which keeps a footer at the bottom of short pages.

Limits and Common Surprises

  • Container only. There are no controls for grid-column, grid-row, grid-template-areas, named lines or alignment; spanning a header across both columns needs grid-column: 1 / -1 on that child.
  • Preview cell count. The preview always draws Columns × Rows cells. If your template has a different number of tracks, the extra cells go into implicit rows, just as real children would.
  • Long content stretches 1fr. A 1fr column has a minimum of auto. With an unbroken URL in the middle cell of a 600px repeat(3, 1fr) grid, the columns came out 9.6px, 751px and 9.6px and overflowed the container; repeat(3, minmax(0, 1fr)) kept them at 200px each.
  • auto-fill vs auto-fit. With two items in a 1000px container, repeat(auto-fill, minmax(180px, 1fr)) kept five 187.2px columns (three empty), while auto-fit collapsed the empty ones and gave each item 492px. A container narrower than 180px overflows; minmax(min(180px, 100%), 1fr) prevents that.
  • The template and gap fields are not validated. An invalid value such as repeat(3 1fr) is copied as written, and the preview keeps showing the last valid template because the browser ignores the invalid value.

The track sizing rules are in CSS Grid Layout Level 2. For one-dimensional rows of items, the flexbox generator is often the simpler fit.

Common Grid Patterns

  • Equal columns — repeat(3, 1fr) creates three equal columns.
  • Sidebar layout — 250px 1fr gives a fixed sidebar and a flexible main area.
  • Holy grail — 200px 1fr 200px columns with auto 1fr auto rows; the header and footer children span all three columns with grid-column: 1 / -1.
  • Responsive tiles — repeat(auto-fill, minmax(180px, 1fr)) auto-wraps at any screen width.

FAQ

What is CSS Grid?

CSS Grid is a two-dimensional layout system built into CSS. It lets you define rows and columns simultaneously, then place elements precisely within a grid container. It's ideal for page-level layouts, card grids, image galleries, and any UI that needs both horizontal and vertical structure.

What does grid-template-columns do?

grid-template-columns defines the number and size of the grid's columns. The generator pre-fills it with repeat(N, 1fr) — N equal-width columns that each take one fractional unit of the available space. You can override this with any valid value, such as 200px 1fr 2fr or repeat(auto-fill, minmax(200px, 1fr)).

What is the difference between column-gap and row-gap?

column-gap sets the space between columns and row-gap sets the space between rows. Together they control the gutters inside the grid. The shorthand is gap: <row-gap> <column-gap>; with one value, both gaps are the same.

What is the 1fr unit?

fr stands for fractional unit. It distributes the remaining free space in the grid container proportionally. For example, 1fr 2fr 1fr creates three columns where the middle column is twice as wide as the other two. A 1fr track never gets narrower than its content's minimum width unless you write minmax(0, 1fr).

How do I make a responsive grid without media queries?

Use auto-fill or auto-fit with minmax(): grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)). This creates as many columns as fit the minimum size and stretches them to fill the remaining space. auto-fit also collapses the empty columns, so a few items stretch across the whole row.

Are my values sent anywhere or saved?

No. The CSS is built in your browser tab, and the counts, gaps and templates are not sent to a server or written to browser storage. The page's analytics records a usage event with the tool name and the action (generate or copy), not the values you typed.