π What is grid-template-rows?
grid-template-rows is a CSS Grid property used to define theheight, number, and behavior of rows inside a grid container. It works just like grid-template-columns, but vertically. With this property, you can create fixed-height rows, flexible rows, auto-sized rows, or even fully responsive vertical layouts.
π Basic Example
Creating 3 Rows
.container {
display: grid;
grid-template-rows: 100px 200px 300px;
}This creates three rows with fixed heights.
π Row Size Units
| Unit | Description |
|---|---|
| px | Fixed height |
| % | Percentage of container height |
| fr | Fractional space distribution |
| auto | Height based on content |
| minmax() | Minimum + Maximum flexible size |
π₯ Using fr Units for Row Flexibility
The fr unit divides the available vertical space proportionally.
Fractional Rows
grid-template-rows: 1fr 2fr 1fr;
/* Middle row is twice as tall */π auto Height Rows
auto Row Example
grid-template-rows: auto auto 1fr;First two rows expand only as much as the content needs; the last row takes up remaining space.
π repeat() for cleaner syntax
Repeat Rows
grid-template-rows: repeat(3, 100px);
/* Same as: 100px 100px 100px */π± Responsive Row Control with minmax()
MinMax Rows
grid-template-rows: minmax(150px, auto) 1fr 2fr;The first row will always be at least 150px, but may grow larger if needed.
π§ Explicit vs Implicit Rows
Explicit Rows
Rows defined using grid-template-rows.
Implicit Rows
When grid items overflow the defined rows, extra rows are created usinggrid-auto-rows.
Implicit Rows Example
.container {
display: grid;
grid-template-rows: 100px 100px;
grid-auto-rows: 80px; /* rows added automatically */
}Note
π§© Practical Layout Example: Header + Content + Footer
Common Web Layout
.layout {
display: grid;
grid-template-rows: 80px 1fr 60px;
height: 100vh;
}β’ Top row = fixed header
β’ Middle row = flexible content
β’ Bottom row = fixed footer

π Visual Examples of grid-template-rows
| Value | Rows Created | Description |
|---|---|---|
| 100px 100px | 2 | Two fixed-height rows |
| 1fr 1fr | 2 | Equal flexible rows |
| repeat(3, auto) | 3 | Fit content automatically |
β οΈ Common Mistakes
- Using only fixed px values β breaks responsiveness
- Forgetting that % units depend on container height
- Not using minmax() for controlled flexibility
- Expecting rows to grow automatically without auto or fr units
Note
π₯ Summary
grid-template-rows defines the vertical structure of your grid. With units like fr, auto, and minmax(), you can build powerful, responsive layouts that adapt naturally to content and screen size.
Explore more here βMDN Docs π