elefcode

CSS Grid Template Areas Builder

Paint named areas onto a grid, set column and row sizes, and get grid-template-areas CSS with a mobile stack — plus HTML and Tailwind.

Start from:
Paint with

Click or drag across cells to paint. Column and row sizes accept any CSS: 1fr, 200px, auto, minmax(0, 65ch).

Grid
.layout {
  display: grid;
  grid-template-columns: 200px 1fr 200px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header header"
    "nav    main   aside"
    "footer footer footer";
  gap: 16px;
  min-height: 100vh;
}

.layout > .header { grid-area: header; }
.layout > .nav { grid-area: nav; }
.layout > .main { grid-area: main; }
.layout > .aside { grid-area: aside; }
.layout > .footer { grid-area: footer; }

/* Below 768px, stack the areas in one column */
@media (max-width: 767px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "header"
      "nav"
      "main"
      "aside"
      "footer";
  }
}
  • On small screens the areas stack in the order of the area list. Reorder the list to change it.

Advertisement

Guide

About the CSS Grid Template Areas Builder

grid-template-areas lets you draw a page layout in CSS as a little text map: each quoted string is a row, and each word names the area that fills that cell. Children then just say which area they belong to with grid-area.

Here you paint the map instead of typing it. The builder keeps the strings aligned, checks each area is a valid rectangle, and writes a mobile layout too.

Areas must be rectangles

Every named area has to form one solid rectangle. An L-shape, or the same name in two separate places, makes the whole grid-template-areas declaration invalid, and the browser silently drops it. The builder outlines any offending area in red.

Rearranging for mobile

Because the layout lives in CSS rather than the HTML order, a media query can redraw it completely. The generated query stacks the areas in one column on small screens, in the order of your area list, without touching the markup.

How to use it

  1. 1Start from a preset or set the number of columns and rows.
  2. 2Add area names and paint them onto the cells.
  3. 3Set column and row sizes and the gap.
  4. 4Copy the CSS and HTML.

Frequently asked questions

What does a dot mean in grid-template-areas?

A . is an empty cell that belongs to no area. Use it for gutters or blank space in the layout.

How is this different from the Flexbox / Grid playground?

That tool explores the alignment properties of flex and grid containers. This one is for designing a named page layout cell by cell.

Can an area span rows and columns?

Yes — paint it across several cells in a rectangle, and it spans them all.

What sizes can I use for columns?

Any CSS track size: 1fr, 200px, auto, 20%, minmax(0, 1fr), fit-content(300px) and so on.

Why use minmax(0, 1fr) instead of 1fr?

1fr will not shrink below its content’s minimum width, so long words or code blocks can overflow. minmax(0, 1fr) allows it to shrink.

Related tools