CSS grid-template-rows Property

Definition
Definition and Usage
The grid-template-rows property sets the size (and optional line names) of the explicit row tracks on a grid container (display: grid).
The initial value is none. Pair it with grid-template-columns for columns, or use the grid-template shorthand. Implicit rows use grid-auto-rows.
Standard-track.Not deprecated and not experimental. Baseline widely available with CSS Grid. The subgrid value is newer—check support if you rely on it.
Syntax
CSS Syntax
grid-template-rows: none | <track-list> | subgrid | initial | inherit;
A track list is one or more sizes such as 40px, 1fr, auto, minmax(), or repeat().
Values
Property Values
| Value | Description | Try it |
|---|
none | Default. No explicit rows | Try it |
<length> / % | Fixed or percentage row height | Try it |
<fr> | Share of remaining free space (needs a definite height) | Try it |
minmax() / repeat() | Range size, or repeat a track pattern | Try it |
initial | Resets to none | Try it |
inherit | Takes the parent value (not inherited by default) | Try it |
Approach
How to Use grid-template-rows
List one size per row, top to bottom. Give the grid a height when using fr.
- Set
display: grid on the container. - Write row sizes:
grid-template-rows: 40px 1fr;. - Set a definite height (for example
height: 160px) so fr rows have free space to share. - Use
repeat() or minmax() for patterns and ranges.
| Value | Result |
|---|
40px 1fr | Fixed header row + flexible body |
1fr 1fr 1fr | Three equal rows |
repeat(3, 1fr) | Same as three 1fr tracks |
minmax(40px, 1fr) 2fr | First row at least 40px; second gets twice the free space |
Try it
Live Preview
Change only grid-template-rows. The demo box has a fixed height so fr can expand.
Code
CSS Examples
Each snippet focuses on grid-template-rows. Use Try It Yourself for a live editor.
Example 1 — Fixed + Flexible
A length sizes one row; 1fr takes the rest of the height.
<style>
.grid {
display: grid;
height: 140px;
grid-template-rows: 40px 1fr;
}
</style>
<div class="grid">
<div>1</div>
<div>2</div>
</div>
How It Works
- Two tracks. The value lists two row sizes, so the grid has two rows.
- Fixed first.
40px locks the first row height. - Flexible second.
1fr takes the remaining free height. - Height matters.
height: 140px gives fr a pool of free space to share.
Example 2 — Equal Rows with repeat()
repeat(3, 1fr) is a short form of 1fr 1fr 1fr.
<style>
.grid {
display: grid;
height: 180px;
grid-template-rows: repeat(3, 1fr);
}
</style>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
How It Works
- Count first.
repeat(3, …) builds three identical tracks. - Equal share. Each track is
1fr, so free height splits three ways. - Same as listing. This matches writing
1fr 1fr 1fr by hand. - One item per row. Three children fill the three explicit rows.
Example 3 — minmax()
Give a row a minimum height while still allowing it to grow.
<style>
.grid {
display: grid;
height: 160px;
grid-template-rows: minmax(40px, 1fr) 2fr;
}
</style>
<div class="grid">
<div>1</div>
<div>2</div>
</div>
How It Works
- Floor and flex.
minmax(40px, 1fr) never shrinks below 40px and can grow with free space. - Larger second share.
2fr gets twice as much free height as a 1fr track. - Two rows. Items stack top to bottom into those tracks.
- Useful for headers. Keeps a readable minimum without locking a forever-fixed height.
Edge Cases & Pitfalls
Row fr tracks need free height. Watch container size and implicit rows.
heightfr needs a definite block size
If the grid’s height is only content-sized, 1fr rows often behave like auto. Set height, min-height, or fill a sized parent.
frfr shares leftover space
Fixed lengths are resolved first. Then fr tracks divide what remains—not the full container height by default.
nonenone still allows implicit rows
With none, rows appear as needed and size via grid-auto-rows.
%Percentages need a definite container size
If the grid’s block size depends on its tracks, browsers may treat a percentage like auto.
subgridsubgrid inherits the parent track sizes
Use it only inside a nested grid that spans parent tracks. Support is solid in modern browsers, but verify if you target older ones.
Compatibility
Browser Support
grid-template-rows is a browser style property for CSS Grid. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
grid-template-rows
Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+, Opera, Samsung Internet 6+. Not supported in Internet Explorer.
Google Chrome 57+
Full support
Mozilla Firefox 52+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 16+
Full support
Opera 44+
Full support
Samsung Internet 6+
Full support
Internet Explorer All
Not supportedgrid-template-rows Supported with modern CSS Grid
Bottom line: Safe for modern grid layouts. No vendor prefix is required in current browsers.
Remember
Key Takeaways
Role: define explicit row count and heights.
fr: shares free height after fixed tracks—needs a definite container height.
Helpers: repeat() for patterns; minmax() for ranges.
Implicit: overflow rows use grid-auto-rows, not this property.
One line: grid-template-rows lists the heights of your explicit grid rows, top to bottom.
Frequently Asked Questions
It defines how many explicit row tracks a grid has and how tall each track is.
none — no explicit rows. Extra rows come from grid-auto-rows when items need them.
One share of the free space left after fixed-size row tracks are sized. The grid container needs a definite height for fr rows to expand.
A compact way to write 1fr 1fr 1fr — three equal flexible rows.
grid-template-rows sizes the explicit rows you declare. grid-auto-rows sizes implicit rows created by overflow or placement.
Baseline widely available: Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+. It is a browser style property, not a Node.js feature.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful