Skip to main content

grid-template-rows Property in CSS Grid Layouts

grid-template-rows specifies the number and heights of rows browsers should display in the selected grid container.

Example 1: Create a Three-Rows Grid Container

section {
display: grid;
grid-template-rows: 95px 1fr 70px;
background-color: orange;
margin: 10px;
padding: 7px;
}

div {
background-color: purple;
color: white;
margin: 5px;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the grid-template-rows property to display three rows of different heights in the selected <section> grid container.

note

We used the fr (fraction) unit to scale the second row relative to the fraction of available space in the grid container.

Example 2: Create a Three-Rows and Four-Columns Grid Container

section {
display: grid;
grid-template-rows: 90px 300px 1fr;
grid-template-columns: auto auto auto auto;
background-color: orange;
margin: 10px;
padding: 7px;
}

div {
background-color: purple;
color: white;
margin: 5px;
padding: 10px;
border-radius: 5px;
}

Try it on StackBlitz

The snippet above used the grid-template-rows property to display three columns of different heights in the selected <section> grid container.

note

You can use the grid-auto-rows property to specify default row heights for all the grid container's rows. For instance, grid-auto-rows: 100px will set default heights of 100px for all rows. But a grid-template-rows declaration will override it.

tip

Use the CSS repeat() function to specify grid-template-rows values with repeated patterns.

Buy your CSS Flexbox Explained Visually book on Amazon

Overview

This article discussed what a CSS grid-template-rows property is. We also used examples to see how it works.