CSS - grid-template-rows

The grid-template-rows CSS property defines the line names and track sizing functions of the grid's rows.

Examples

CSS

CSS
#grid {
  display: grid;
  height: 100px;
  grid-template-rows: 30px 1fr;
}

#areaA {
  background-color: lime;
}

#areaB {
  background-color: yellow;
}

HTML

HTML
<div id="grid">
  <div id="areaA">A</div>
  <div id="areaB">B</div>
</div>

Result

Syntax  

CSS
/* Keyword value */
grid-template-rows: none;

/* <track-list> values */
grid-template-rows: 100px 1fr;
grid-template-rows: [linename] 100px;
grid-template-rows: [linename1] 100px [linename2 linename3];

/* <auto-track-list> values */
grid-template-rows: 200px repeat(auto-fill, 100px) 300px;
grid-template-rows: minmax(100px, max-content)
                       repeat(auto-fill, 200px) 20%;
grid-template-rows: [linename1] 100px [linename2]
                       repeat(auto-fit, [linename3 linename4] 300px)
                       100px;
grid-template-rows: [linename1 linename2] 100px
                       repeat(auto-fit, [linename1] 300px) [linename3];

/* Subgrid values */
grid-template-rows: subgrid;
grid-template-rows: subgrid [linename1];
grid-template-rows: subgrid repeat(4, [linename1]);
grid-template-rows: subgrid repeat(4, [linename1 linename2]);
grid-template-rows: subgrid repeat(auto-fill, [linename1]);

/* Global values */
grid-template-rows: inherit;
grid-template-rows: initial;
grid-template-rows: unset;

Values

none
Is a keyword meaning that there is no explicit grid. Any rows will be implicitly generated and their size will be determined by the grid-auto-rows property.
subgrid
Is a keyword indicating that the grid will align to its parent grid in that axis. Rather than specifying the sizes of rows explicitly, they’ll be taken from the parent grid’s definition.
<length>
Is a non-negative length.
<percentage>
Is a non-negative <percentage> value relative to the block size of the grid container. If the block size of the grid container is indefinite, the percentage value is treated like auto.
<flex>
Is a non-negative dimension with the unit fr specifying the track’s flex factor. Each <flex>-sized track takes a share of the remaining space in proportion to its flex factor.

When appearing outside a minmax() notation, it implies an automatic minimum (i.e. minmax(auto, <flex>)).

max-content
Is a keyword representing the largest maximal content contribution of the grid items occupying the grid track.
min-content
Is a keyword representing the largest minimal content contribution of the grid items occupying the grid track.
minmax(min, max)
Is a functional notation that defines a size range greater than or equal to min and less than or equal to max. If max is smaller than min, then max is ignored and the function is treated as min. As a maximum, a <flex> value sets the track’s flex factor. As a minimum, it is treated as zero (or minimal content, if the grid container is sized under a minimal content constraint).
auto
Is a keyword that is identical to maximal content if it's a maximum. As a minimum it represents the largest minimum size (as specified by min-width/min-height) of the grid items occupying the grid track.

Note: auto track sizes (and only auto track sizes) can be streched by the align-content and justify-content properties.

Formal syntax

CSS
none <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a href="css/grid-template-rows#track-list"><track-list></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a href="css/grid-template-rows#auto-track-list"><auto-track-list></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> subgrid <a href="css/grid-template-rows#line-name-list"><line-name-list></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a><p>where <br><code><track-list> = <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#track-size"><track-size></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a href="css/grid-template-rows#track-repeat"><track-repeat></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a><br><auto-track-list> = <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#fixed-size"><fixed-size></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a href="css/grid-template-rows#fixed-repeat"><fixed-repeat></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#auto-repeat"><auto-repeat></a> <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#fixed-size"><fixed-size></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a href="css/grid-template-rows#fixed-repeat"><fixed-repeat></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a><br><line-name-list> = <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <name-repeat> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a></code></p><p>where <br><code><line-names> = '<a title="Brackets" href="css/value_definition_syntax#brackets">[</a>' <custom-ident><a title="Asterisk" href="css/value_definition_syntax#asterisk_(*)">*</a> '<a title="Brackets" href="css/value_definition_syntax#brackets">]</a>'<br><track-size> = <a href="css/grid-template-rows#track-breadth"><track-breadth></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> minmax( <a href="css/grid-template-rows#track-breadth"><track-breadth></a> , <a href="css/grid-template-rows#track-breadth"><track-breadth></a> )<br><track-repeat> = repeat( <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <positive-integer> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> , <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a href="css/grid-template-rows#track-size"><track-size></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> )<br><fixed-size> = <a href="css/grid-template-rows#fixed-breadth"><fixed-breadth></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> minmax( <a href="css/grid-template-rows#fixed-breadth"><fixed-breadth></a> , <a href="css/grid-template-rows#track-breadth"><track-breadth></a> )<br><fixed-repeat> = repeat( <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <positive-integer> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> , <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a href="css/grid-template-rows#fixed-size"><fixed-size></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> )<br><auto-repeat> = repeat( <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> auto-fill <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> auto-fit <a title="Brackets" href="css/value_definition_syntax#brackets">]</a> , <a title="Brackets" href="css/value_definition_syntax#brackets">[</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> <a href="css/grid-template-rows#fixed-size"><fixed-size></a> <a title="Brackets" href="css/value_definition_syntax#brackets">]</a><a title="Plus" href="css/value_definition_syntax#plus_(.2b)">+</a> <a href="css/grid-template-rows#line-names"><line-names></a><a title="Question mark" href="css/value_definition_syntax#question_mark_(.3f)">?</a> )</code></p><p>where <br><code><track-breadth> = <a href="css/grid-template-rows#length-percentage"><length-percentage></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <flex> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> min-content <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> max-content <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> auto<br><fixed-breadth> = <a href="css/grid-template-rows#length-percentage"><length-percentage></a><br></code></p><p>where <br><code><length-percentage> = <a title="Possible values: a number followed by'em', 'ex', 'ch', 'rem', 'px', 'cm', 'mm', 'in', 'vh', 'vw', 'vmin', 'vmax', 'pt', 'pc' or 'px', like 3px, 1.5cm, -0.5em or 0" href="css/length"><length></a> <a title="Single bar" href="css/value_definition_syntax#single_bar">|</a> <a title="" href="css/percentage"><percentage></a></code></p>

Description  

The grid-template-rows CSS property defines the line names and track sizing functions of the grid's rows.

Initial valuenone
Applies togrid containers
Inheritedno
Percentagesrefer to corresponding dimension of the content area
Mediavisual
Computed valueas specified, but with relative lengths converted into absolute lengths
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Browser Compatibility  

Feature Chrome Firefox (Gecko) Internet Explorer Edge Opera Safari
Basic support 29.0[1] 40.0 (40.0)[2] 10.0-ms[3] 20-ms[3] 28.0[1] Nightly build-webkit
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support No support 10.0-ms[3] No support No support

[1] Implemented behind the experimental Web Platform features flag in chrome://flags.

[2] Implemented behind the preference layout.css.grid.enabled, defaulting to false.

[3] Internet Explorer implements an older version of the specification using the -ms prefix. Therefore the property is implemented there as -ms-grid-rows.

See Also  

Specifications  

Specification Status Comment
CSS Grid Layout
The definition of 'grid-template-rows' in that specification.
Working Draft Initial definition

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/css/grid-template-rows

CSS CSS Grid CSS Property Reference