Placing Grid Items Vertically
You'll learn how to position grid items by specifying exactly which horizontal row lines they should span between.
What Are grid-row-start and grid-row-end?
Just like grid-column-start and grid-column-end control horizontal placement, grid-row-start and grid-row-end control vertical placement of grid items. These properties let you say "start this item at row line 2 and end it at row line 4," giving you precise control over which rows your item occupies.
Think of it like booking hotel floors: you might say "I need floors 3 through 5" — that's specifying both where you start and where you end vertically.
How It Works
Grid rows are defined by horizontal lines running across your grid. These lines are numbered starting at 1 (the top edge) and incrementing downward:
.grid-container {
display: grid;
grid-template-rows: 100px 100px 100px;
/* Creates 4 row lines: top (1), after first (2), after second (3), bottom (4) */
}
.item {
grid-row-start: 1; /* Start at the top line */
grid-row-end: 3; /* End at the third line (spans 2 rows) */
}
This item now occupies rows 1 and 2 because it starts at line 1 and ends before line 3.
You can also count backwards using negative numbers, where -1 is the last line:
.footer {
grid-row-start: -2; /* Second-to-last line */
grid-row-end: -1; /* Last line */
}
Key Takeaway: grid-row-start and grid-row-end position items vertically by specifying which horizontal row lines they begin and end at, giving you row-by-row control over grid layout.