CSS Grid Generator

Draw a grid layout and copy the CSS and HTML for it

Loading CSS Grid Generator...
Please wait a moment

How to Build a CSS Grid Layout - Step by Step

Step 1

Set Up the Columns and Rows

A CSS grid starts with its tracks. Pick a preset or press Clear, then choose how many columns and rows you need (up to 12 of each) and give every track a size.

•
Track sizes: 1fr shares free space, 200px or 25% is fixed, auto fits the content, and minmax(100px, 1fr) sets a floor and a ceiling
•
Gaps: column and row gaps are set separately; equal values are written as a single gap line
•
Min height: rows sized in fr only get room when the container has a height, so the presets set a min-height you can change or clear
•
Alignment: justify-items, align-items, justify-content and align-content are left out of the CSS unless you choose a value
Step 2

Place Your Items

Drag across the dashed cells in the preview to create an item that spans them. On a phone, tap the start cell and then the end cell. Each item shows up in the list on the left, where you can rename it and fine-tune its grid-column and grid-row lines by number.

•
Keyboard: Tab to a cell and press Enter on the start and end cells, or use Add item and type the line numbers
•
Named areas: with simple names like header and main and no overlaps, the output uses grid-template-areas
•
Overlaps: items may overlap on purpose (an image with a caption on top, say); the tool warns you and switches to line numbers
•
Card grids: the Auto-fit cards mode skips placement and writes repeat(auto-fit, minmax(200px, 1fr)) instead
Step 3

Copy the CSS and HTML

The CSS tab holds a .grid-container rule plus one class per item; the HTML tab has the markup that uses those classes. For the holy grail preset the CSS looks like this:

.grid-container {
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header  header  header"
    "sidebar main    aside"
    "footer  footer  footer";
  gap: 16px;
  min-height: 400px;
}

.header {
  grid-area: header;
}
•
Copy: copies whichever tab is open, exactly as shown
•
Download grid.css: saves the CSS tab as a file
•
Class names: an item called "Main Content" becomes .main-content, and the tool says so in the notes

Frequently Asked Questions

How do I make a layout with this CSS grid generator?

Pick a preset or press Clear, set how many columns and rows you want, and type a size for each one (1fr, 200px, 25%, auto or minmax(100px, 1fr)). Then drag across the preview to create an item, or tap a start cell and an end cell on a phone. Each item gets a name you can change, and the CSS and HTML below the preview update as you go.

When does the generator use grid-template-areas?

When the "Use grid-template-areas" box is ticked and the layout allows it: every item name is a plain CSS identifier like header or main-content, names are unique, no two items overlap and every item sits inside the grid. Then the container gets a grid-template-areas map and each item gets grid-area: name. If any of that is not true, the generator writes grid-column and grid-row line numbers instead and tells you why.

Is the preview the same as the CSS I copy?

Yes. The preview is styled from the same list of declarations that is printed in the CSS tab, so the track sizes, gaps, alignment and item positions you see are the ones you get. The only extras in the preview are the colours, the dashed cell lines and a 14px font, which are there so you can see the grid.

What happens if I type a track size the browser does not understand?

The field turns red and a message names the column or row and the value, for example Column 2: "abc" is not a track size. While a size is wrong the preview and the code are hidden, so you never copy CSS with a track quietly missing. repeat() inside a single field is refused too, because the Columns and Rows counts already handle repetition.

How do I make a responsive card grid without media queries?

Choose Auto-fit cards (or the Card grid preset). The generator writes grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)), so the browser fits as many 200px-or-wider columns as the container allows and stretches them to fill the row. Switch to auto-fill if you want empty column slots kept when there are only a few cards.

When should I use CSS Grid instead of Flexbox?

Grid is the better fit when you care about rows and columns at the same time: page shells, dashboards, galleries, forms that line up in columns. Flexbox suits one direction at a time, like a toolbar or a row of buttons that should wrap. The two work well together, for example a grid page with a flex navigation bar inside the header.

Does my layout get uploaded anywhere?

No. The grid is built in your browser and nothing is sent to our server or kept after you leave, so a reload starts from the default layout again.

Laying out a single row or column? The CSS flexbox generator is the simpler tool for that. Once your stylesheet is done, tidy it with the CSS formatter or shrink it with the CSS minifier.