CSS grid-template-rows
- type
- property
- applies to
- grid containers
- inherits
- no
- common values
- auto 1fr auto; repeat(3, 120px); minmax(200px, auto)
Where it goes
On the grid parent, next to display: grid, when rows need fixed or shared heights. Give the parent a height or min-height, or 1fr has no spare room to take.
Example
.page {
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
}
.gallery {
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(160px, auto);
}Common mistakes
- Writing grid-template-rows: 1fr 1fr and getting rows that grow to the tallest content anyway. 1fr shares the parent's height, so with no height on the parent there is nothing to share.
- Setting fixed px rows and watching content spill out of them. Content does not shrink to fit a row. minmax(120px, auto) sets a minimum but lets the row grow.
- Defining three rows and adding a fourth item. The extra row is sized by grid-auto-rows (auto by default), not by your list.