CSS Grid Generator

Design a CSS Grid layout with a live preview. Set rows, columns, track sizes, and gaps, place named areas, and copy the CSS and matching HTML.

Grid settings

Layout preset
Track sizes

Use one track size per field, such as 1fr, 120px, auto, or minmax(8rem, 1fr).

Grid preview

Select an area to edit it, or an empty cell to add one.

CSS

.layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: 48px minmax(120px, 1fr) 40px;
  gap: 12px;
  grid-template-areas:
    "header header header"
    "sidebar main main"
    "footer footer footer";
}

.layout__header { grid-area: header; }

.layout__sidebar { grid-area: sidebar; }

.layout__main { grid-area: main; }

.layout__footer { grid-area: footer; }

HTML

<div class="layout">
  <div class="layout__header">header</div>
  <div class="layout__sidebar">sidebar</div>
  <div class="layout__main">main</div>
  <div class="layout__footer">footer</div>
</div>

Build a CSS Grid layout

Start with a page layout, a card grid, or an empty grid. Set the number of columns and rows, then adjust the gaps between them. Under Track sizes, give each track its own width or height. For example, a 12rem sidebar alongside a 1fr content column leaves the remaining space for content.

Place items with named grid areas

Select an empty cell and then the opposite corner of the rectangle. Select the same cell twice to use a single cell. Select an existing area to rename or remove it. The generated CSS uses grid-template-areas on the container and grid-area on each item. Each name must occupy a rectangle, so a new area needs its own cells.

Copy CSS and HTML to your project

Copy the CSS to your stylesheet and the HTML to your page or component. The generated class names connect the elements to their areas. Replace the placeholder text with your own content. Use units such as fr, rem, and %, or a track like minmax(8rem, 1fr), to let the layout respond to its container.

Understand tracks and gaps

A track is the space taken by one row or column. An fr track gets a share of the remaining space, while auto can size a track to its content. A gap adds space between neighboring tracks. Use padding on the container when you need space around the entire grid.