DevTools Logo

CSS Grid Named Areas Builder

CSS Grid Named Areas Builder

Paint named areas on a grid and generate valid grid-template-areas CSS in your browser

Runs in your browser
Try an example

Grid editor

3 x 3

Click a cell to paint it with this name. Type a dot (or leave it empty) to paint an empty cell; right-click or Shift-click also erases.

One size repeats for every track (1fr); or list one per track, e.g. 200px 1fr auto.

Generated CSS

4 named areas
.grid-container {
  display: grid;
  grid-template-areas:
  "header header header"
  "sidebar main main"
  "sidebar footer footer";
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: 1fr 1fr 1fr;
}
  .header { grid-area: header; }
  .sidebar { grid-area: sidebar; }
  .main { grid-area: main; }
  .footer { grid-area: footer; }
  • header: row 1, column 1-3
  • sidebar: row 2-3, column 1
  • main: row 2, column 2-3
  • footer: row 3, column 2-3

Live preview

Examples

Header over sidebar gap

Input
[["header", "header"], [".", "main"]]
Output
templateAreas: '"header header"\n  ". main"' + .header / .main grid-area rules

Dots stay literal placeholders in quoted rows, and each named area gets exactly one grid-area rule.

Smallest valid grid

Input
[["card"]]
Output
valid: true, templateAreas: '"card"', css with 1fr row/column plus .card rule

A 1x1 matrix is the minimum accepted grid and emits a single template row and rule.

About this tool

CSS Grid Named Areas Builder validates a string matrix with validateGridAreas(matrix): it rejects empty or ragged grids (Grid must contain at least one cell.), enforces CSS-identifier area names (Invalid area name ".."), and requires every named area to fill a solid rectangle — any L-shaped or disconnected footprint fails with Area "nav" must form a solid rectangle (L-shaped or disconnected areas are not allowed). "." cells and blank strings are empty placeholders, and areas returns first-seen names in order.

buildGridCss(matrix, rowSize = "1fr", columnSize = "1fr") emits the stylesheet regardless of validity: templateAreas quotes each row ("header header" / ". main", joined with \n plus two-space indent), the container sets display: grid with grid-template-areas, grid-template-rows (one rowSize per row), and grid-template-columns (one columnSize per column), then one .<name> { grid-area: <name>; } rule per area in first-seen order.

The minimum grid is a single cell: [["card"]] validates true with templateAreas '"card"' and one .card rule, and building is deterministic — the same matrix always yields the same templateAreas and css strings.

How to use this tool

  1. Lay out the matrix

    Provide rows of area names with "." for empty cells; validateGridAreas reports validity, message, and the ordered area list.

  2. Keep areas rectangular

    Fill each name's bounding box completely — L-shaped or split footprints are rejected with the solid-rectangle message.

  3. Copy the CSS

    Call buildGridCss(matrix) and paste .grid-container plus the per-area .<name> { grid-area: <name>; } rules into your stylesheet.

Use cases

Prototyping page shells

Sketch header/sidebar/main layouts as a name matrix and copy the grid-template-areas block into CSS.

Catching non-rectangular areas

Validate hand-drawn ASCII layouts and get the exact L-shaped area name to fix before writing CSS.

Teaching grid areas

Show how dots create gutters and how each quoted row maps to one grid-template row track.

Common mistakes

Mistake:Drawing L-shaped or split areas.

Fix:Every name must fill its full bounding rectangle — move the stray cell or rename it so each area is one solid block.

Mistake:Using invalid area names.

Fix:Names must match a CSS identifier (letters, digits, _/-; no leading digit) — rename "1st" to "first" and avoid spaces.

Mistake:Feeding ragged rows.

Fix:Every row needs the same column count; pad short rows with "." so the matrix is a true rectangle.

Frequently asked questions

What does this tool do?

It validates a name matrix with validateGridAreas and emits stylesheets with buildGridCss: quoted grid-template-areas rows, display: grid container with 1fr row/column tracks by default, and one .<name> { grid-area: <name>; } rule per area.

What passes validation, and what fails?

[["card"]] is the minimum valid 1x1 grid; [["header","header"],[".","main"]] keeps dot placeholders as '". main"'; and [["nav","nav"],["nav","."]] fails with Area "nav" must form a solid rectangle (L-shaped or disconnected areas are not allowed).

Is my layout uploaded or stored?

No. Validation and CSS emission are pure client-side string building — grid data never leaves your browser.

What does the CSS output contain?

A .grid-container with grid-template-areas (each row a quoted string), grid-template-rows/columns with one track per row/column, plus exactly one grid-area rule per named area in first-seen order.

References & standards