CSS grid-template-rows Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The grid-template-rows property defines the number and size of row tracks in a CSS grid container.

01

Rows

Track sizes.

02

none

Default.

03

1fr

Flexible.

04

auto

Content.

05

repeat()

Patterns.

06

minmax()

Range.

Introduction

The grid-template-rows property in CSS is a key component of the CSS Grid Layout system. It defines the size of each row in a grid container, allowing you to create complex and responsive grid layouts. This property helps in organizing and aligning grid items within rows, providing control over the layout of your web content.

Definition and Usage

Set grid-template-rows on a grid container with display: grid. List track sizes separated by spaces, or use functions like repeat() and minmax() for flexible patterns. Pair with grid-template-columns to define the full grid structure.

💡
Beginner Tip

100px 1fr auto creates three rows: a fixed header height, a flexible main area, and a footer sized by its content.

📝 Syntax

The syntax for the grid-template-rows property uses a space-separated list of row sizes. Each size can be a length, a percentage, the fr unit, or the auto keyword:

syntax.css
.container {
  grid-template-rows: value;
}

Basic Example

grid-template-rows-basic.css
.grid-container {
  display: grid;
  grid-template-rows: 100px 1fr auto;
}

With repeat()

grid-template-rows-repeat.css
.grid-container {
  grid-template-rows: repeat(3, 1fr);
}
grid-template-rows: none; grid-template-rows: 100px 1fr auto; repeat(4, minmax(80px, 1fr))

Default Value

The default value of the grid-template-rows property is none, which means the rows of the grid will be auto-sized based on the content.

Syntax Rules

  • Applies to grid containers only, not individual grid items.
  • Accepts length, percentage, fr, auto, minmax(), and repeat().
  • Each value creates one row track unless wrapped in repeat().
  • The property is not inherited.
  • Set an explicit height on the container when using fr row tracks.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toGrid containers
InheritedNo
ControlsRow track sizes
Flexible unitfr (fraction)

💎 Property Values

ValueDescription
lengthA specific length value, such as 100px or 2em, that sets the exact size of the row
percentageA percentage of the grid container’s height, such as 50%
frA fraction of the available space. For example, 1fr and 2fr share space in a 1:2 ratio
autoThe row size is determined by its content
minmax(min, max)Defines a minimum and maximum row size range
repeat(count, track-size)Repeats a row size pattern a specified number of times

👀 Live Preview

Three rows with grid-template-rows: 2rem 1fr 2.5rem (middle row flexible):

Row 1
Row 2
Row 3

Examples Gallery

Create fixed, flexible, and auto rows, use repeat() for equal heights, apply minmax() for bounds, and build a full-height page layout.

🔢 Row Track Sizing

Start with the reference example — fixed, flexible, and content-sized rows.

Example 1 — 100px, 1fr, and auto

Create a grid layout with three rows of different sizes: fixed height, flexible, and automatic.

grid-template-rows-fixed-flex.css
.grid-container {
  display: grid;
  grid-template-rows: 100px 1fr auto;
  gap: 10px;
  min-height: 300px;
}
Try It Yourself

How It Works

The first row stays at 100px. The middle 1fr row grows to fill remaining container height. The last auto row sizes to its content.

Example 2 — Three Equal Rows with repeat()

Use repeat() to create multiple equal-height row tracks.

grid-template-rows-repeat-example.css
.grid-container {
  grid-template-rows: repeat(3, 1fr);
  min-height: 300px;
}
Try It Yourself

How It Works

repeat(3, 1fr) is shorthand for 1fr 1fr 1fr, splitting container height into three equal rows.

📈 Responsive Row Patterns

Use minmax() and page layouts for flexible vertical structures.

Example 3 — minmax() for Row Bounds

Set minimum and maximum row heights so rows stay readable.

grid-template-rows-minmax.css
.grid-container {
  grid-template-rows: repeat(4, minmax(80px, 1fr));
  min-height: 400px;
}
Try It Yourself

How It Works

Each row is at least 80px tall but can grow to share vertical space equally with 1fr as the maximum.

Example 4 — Full-Height Page Layout

Combine fixed header and footer rows with a flexible main content row.

grid-template-rows-page.css
.page {
  display: grid;
  grid-template-rows: 60px 1fr 40px;
  min-height: 100vh;
}
Try It Yourself

How It Works

With min-height: 100vh, the middle 1fr row fills all space between the fixed header and footer.

♿ Accessibility

  • Ensure sufficient row height for readable text and touch targets.
  • Test at narrow and zoomed viewports when using fixed pixel row heights.
  • Keep DOM order logical when rows reorder visually on small screens.
  • Use semantic HTML such as <header>, <main>, and <footer>.
  • Do not rely on row position alone to convey meaning; use headings and landmarks.

🧠 How grid-template-rows Works

1

Grid container is created

display: grid enables grid formatting context.

Grid
2

Row tracks are defined

You list sizes like px, fr, auto, or repeat() for each row track.

Rows
3

Browser sizes tracks

Fixed sizes apply first; fr units share remaining vertical space.

Sizing
=

Structured row layout

Items auto-place into rows or span them with grid placement properties.

🖥 Browser Compatibility

The grid-template-rows property is widely supported in modern browsers, including recent versions of Chrome, Firefox, Safari, Edge, and Opera.

Baseline · Modern browsers

grid-template-rows everywhere

Row track sizing works in all major modern grid implementations.

97% Modern browser support
Google Chrome 57+ · Desktop & Mobile
Full support
Mozilla Firefox 52+ · Desktop & Mobile
Full support
Apple Safari 10.1+ · macOS & iOS
Full support
Microsoft Edge 16+ · 79+ Chromium
Full support
Opera 44+
Full support
grid-template-rows property 97% supported

Bottom line: Safe for modern projects. Set container height when using fr row tracks.

🎉 Conclusion

The grid-template-rows property is essential for creating well-structured grid layouts in CSS. By defining the size of rows, you can create flexible and responsive designs that adapt to different screen sizes and content types.

Experiment with various values to see how they affect the layout and achieve the design you envision. Start with fixed, fr, and auto rows, then explore repeat() and minmax() for more control.

💡 Best Practices

✅ Do

  • Use fr for flexible main content rows
  • Set min-height or height when using fr rows
  • Use auto for content-driven footer rows
  • Pair with grid-template-columns
  • Test layouts at different viewport heights

❌ Don’t

  • Apply on grid items instead of containers
  • Expect fr rows to expand without container height
  • Use too many fixed px rows on mobile
  • Forget display: grid on the container
  • Confuse auto with 1fr without testing

Key Takeaways

Knowledge Unlocked

Five things to remember about grid-template-rows

Use these points when sizing grid rows.

5
Core concepts
none 02

Default none

Auto size.

Default
1fr 03

Fraction

Flexible.

Syntax
auto 04

Content

Fits text.

Pattern
repeat 05

repeat()

Equal rows.

Responsive

❓ Frequently Asked Questions

grid-template-rows defines the number and size of row tracks in a CSS grid container.
The default is none, which means rows are auto-sized based on content unless you define them explicitly.
1fr means one fraction of the remaining free vertical space in the grid container after fixed-size row tracks are calculated.
grid-template-rows sets vertical row track sizes. grid-template-columns sets horizontal column track sizes.
auto sizes a row to fit its content. 1fr shares leftover container height with other fr tracks after fixed sizes are applied.

Practice in the Live Editor

Open the HTML editor, change grid-template-rows values, and see how row heights update.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful