Implicit Grid Tracks and auto-rows/auto-columns
You'll learn how to control the size of grid rows and columns that CSS Grid creates automatically when your content exceeds your explicit grid definition.
What Are Implicit Grid Tracks?
Remember that CSS Grid has both explicit and implicit grids. You explicitly define tracks with grid-template-columns and grid-template-rows. But what happens when you have more items than fit in your defined grid? Grid automatically creates extra tracks for those overflow items—these are implicit tracks.
By default, implicit tracks size themselves to fit their content (similar to auto). But you can control their size!
Controlling Implicit Track Sizes
grid-auto-rows sets the size of automatically generated rows:
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: 100px;
}
If you place 10 items in this grid, the first 3 fill the first row (your explicit grid has only columns defined). The remaining 7 items create implicit rows, each 100px tall.
grid-auto-columns works the same way for columns:
.grid-container {
display: grid;
grid-template-rows: repeat(2, 150px);
grid-auto-columns: 200px;
}
Think of It Like This
Imagine setting up folding chairs for a party. You explicitly arrange 3 rows of 4 chairs each (grid-template-rows and grid-template-columns). But 20 guests arrive! Grid automatically adds more rows. grid-auto-rows is like saying "any extra rows you add, make them the same spacing as the original ones."
You can use any sizing value: fr units, minmax(), fixed sizes, or auto.
Key Takeaway: Use grid-auto-rows and grid-auto-columns to control the size of tracks that Grid creates automatically when you have more content than your explicit grid definition can hold.