Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Grid

The grid-template-rows property

Reference for grid-template-rows: define grid row tracks with lengths, fr, minmax(), repeat() and named lines, and see how rows differ from columns.

The grid-template-rows property defines the rows of a grid: how many, how tall, and optionally the names of the lines between them. It uses exactly the same track syntax as grid-template-columns. Rows you don't define explicitly are created on demand and sized by grid-auto-rows.

CSS
.page { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; }

That declaration is the classic "sticky footer" layout: header and footer take their natural height, and the middle row takes all the rest.

Try it

Header, content, footer
Fixed rows and an implicit row

The first two rows follow the list (40px and 70px); the third is created automatically at 24px by grid-auto-rows.

Syntax

CSS
grid-template-rows: none
  | <track-list>
  | <auto-track-list>
  | subgrid <line-name-list>?;
  • Initial value: none
  • Applies to: grid containers
  • Inherited: no
  • Animatable: yes, when the lists have matching structure
  • Computed value: the keyword none or the list with lengths made absolute

Values

Value Description
none No explicit rows; all rows are implicit.
<length> A fixed height.
<percentage> A percentage of the container's height. It only works when the container has a definite height; otherwise it behaves like auto.
<flex> (1fr) A share of the free height. It only gets free space if the container has a definite height.
auto, min-content, max-content Sized from the row's content.
minmax(min, max), fit-content() Bounded sizes.
repeat(n, tracks) Repeats a pattern. auto-fill and auto-fit need a definite height or max-height.
[name] Names a row line.
subgrid Uses the parent grid's row tracks.

Usage notes

  • Height decides fr. With height: auto, rows grow to their content, so 1fr rows just fit their content and equal-height rows need minmax(0, 1fr) plus a set height.
  • Most grids only need columns. If you only write grid-template-columns, rows are created automatically as auto, which is usually what you want for content that flows downward.
  • Page-height layouts. Use min-height: 100vh (or 100dvh) on the container to make an auto 1fr auto layout fill the screen.
  • Overflow. Content larger than a fixed row overflows its cell. Prefer minmax(80px, auto) when the content length is unknown.

Browser support

Supported in all current browsers.