Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

The grid-template property

Reference for the CSS grid-template shorthand: define rows, columns and named areas in one declaration, with the slash syntax, area strings and live examples.

The grid-template property sets the explicit grid in one declaration: grid-template-rows, grid-template-columns and grid-template-areas. It has two forms. The simple form is rows / columns. The area form draws the layout as strings, with row sizes beside each string and column sizes after a slash.

Unlike grid, it leaves the automatic-placement properties (grid-auto-*) alone.

CSS
.simple { grid-template: 80px 1fr / 200px 1fr; }
.areas {
  grid-template:
    "header header" 60px
    "nav    main"   1fr
    / 160px 1fr;
}

Try it

Page layout drawn as strings

The strings name the cells, the sizes after each string set that row's height, and the sizes after the slash set the column widths. One declaration describes the whole page.

The rows / columns form

Syntax

CSS
grid-template: none
  | <'grid-template-rows'> / <'grid-template-columns'>
  | [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <explicit-track-list> ]?;
  • Initial value: none
  • Applies to: grid containers
  • Inherited: no
  • Animatable: the track lists can animate when they have matching structure; areas cannot
  • Computed value: as specified for each longhand

Values

Value Description
none No explicit rows, columns or areas.
<rows> / <columns> Track lists for rows, a slash, then track lists for columns.
"a b" 60px A string of area names (one name per column) followed by an optional row size.
/ <columns> After the strings, an optional slash and the column track list.
. inside a string A cell that belongs to no area.

Usage notes

  • Same number of cells per string. Every string must name the same number of columns, and each named area must form a rectangle.
  • Missing sizes. A row without a size is auto. A missing column list leaves columns as auto, so give columns after the slash in most layouts.
  • Resets. Any of the three longhands you don't supply returns to its initial value.
  • Readable layout. Align the strings in columns, as in the examples, so the picture is visible in your code.
  • When to use grid instead. Reach for grid only if you also want to set grid-auto-flow and the auto track sizes in the same line.

Browser support

Supported in all current browsers.