CSS grid-row-end Property
The CSS grid-row-end property specifies the ending grid line of a grid item along the row axis.
It works with grid-row-start to determine which rows an item occupies. You can use numbered lines, named lines, or the span keyword to control the ending boundary. When the ending position is automatic, CSS Grid determines it from the item's placement and span.
grid-row-end Syntax
The grid-row-end property accepts a grid line position, a span, or the auto keyword.
Basic Syntax
selector {
grid-row-end: auto;
}
Numbered Grid Line
.item {
grid-row-end: 4;
}
Negative Grid Line
.item {
grid-row-end: -1;
}
Named Grid Line
.item {
grid-row-end: content-end;
}
Span a Number of Rows
.item {
grid-row-end: span 3;
}
Span to a Named Line
.item {
grid-row-end: span section;
}
Automatic Ending Line
.item {
grid-row-end: auto;
}
CSS-Wide Keywords
.item {
grid-row-end: initial;
}
.item {
grid-row-end: inherit;
}
.item {
grid-row-end: unset;
}
.item {
grid-row-end: revert;
}
.item {
grid-row-end: revert-layer;
}
Grid line numbers cannot be zero. A span count must be a positive integer. Lengths and percentages are not valid values for this property.
Property Values
The grid-row-end property supports the following values.
| Value | Description |
|---|---|
auto |
Allows automatic placement or an automatic span. |
<integer> |
Specifies a numbered grid line. Negative values count backward from the end of the explicit grid. |
<custom-ident> |
References a named grid line. |
<integer> <custom-ident> |
Identifies a particular occurrence of a named grid line. |
span <integer> |
Specifies the number of row tracks the item spans. |
span <custom-ident> |
Determines the span using a named grid line. |
initial |
Resets the property to auto. |
inherit |
Inherits the computed value from the parent. |
unset |
Resets this non-inherited property to auto. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | No |
| Applies to | Grid items and absolutely positioned boxes whose containing block is a grid container |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
| Related shorthand | grid-row |
The property determines an ending boundary rather than a row height. Use grid-template-rows or grid-auto-rows to control row sizing.
How It Works
CSS Grid uses grid-row-start and grid-row-end to establish the row area occupied by an item.
Create a Grid Container
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(4, 80px);
gap: 12px;
}
Set the Starting and Ending Lines
.item {
grid-row-start: 2;
grid-row-end: 4;
}
The item begins at row line 2 and ends at line 4, occupying the second and third rows.
Change the Ending Line
.item {
grid-row-start: 2;
grid-row-end: 5;
}
Changing the ending line to 5 extends the item through the fourth row.
Important Consideration
The ending line identifies the boundary after the last occupied row. It does not indicate an additional row that the item occupies.
Grid Line Numbering
Grid lines mark the boundaries between tracks. Four explicitly defined rows create five row boundary lines.
Define Four Rows
.container {
display: grid;
grid-template-rows: repeat(4, 80px);
}
End After the First Row
.item {
grid-row-start: 1;
grid-row-end: 2;
}
End After the Third Row
.item {
grid-row-start: 1;
grid-row-end: 4;
}
End After the Fourth Row
.item {
grid-row-start: 1;
grid-row-end: 5;
}
| Ending Line | Rows Occupied When Starting at Line 1 |
|---|---|
2 |
Row 1 |
3 |
Rows 1 and 2 |
4 |
Rows 1, 2, and 3 |
5 |
Rows 1 through 4 |
The starting boundary is required to interpret how many rows a particular ending line covers.
Spanning Rows
The span keyword lets you specify how many rows an item should occupy without calculating its ending line manually.
Span Two Rows
.item {
grid-row-start: 1;
grid-row-end: span 2;
}
Span Three Rows
.item {
grid-row-start: 2;
grid-row-end: span 3;
}
The second example begins at line 2 and spans three rows, ending at line 5.
Equivalent Numbered Ending Line
.item {
grid-row-start: 2;
grid-row-end: 5;
}
Span with Automatic Placement
.item {
grid-row-start: auto;
grid-row-end: span 2;
}
The placement algorithm selects a suitable starting position while maintaining the two-row span.
Important Consideration
A span count must be greater than zero. If the required rows extend beyond the explicit grid, CSS Grid may create implicit rows.
Negative Line Numbers
Negative grid line numbers count backward from the ending boundary of the explicit grid.
End at the Last Explicit Line
.item {
grid-row-start: 1;
grid-row-end: -1;
}
The item extends from the first row line to the final explicit row line.
End One Line Earlier
.item {
grid-row-start: 1;
grid-row-end: -2;
}
Use the Last Explicit Row
.item {
grid-row-start: -2;
grid-row-end: -1;
}
Important Consideration
Negative line numbers refer to the explicit grid. They do not automatically follow the last implicitly generated row.
Named Grid Lines
Named grid lines allow an item's ending boundary to be identified using descriptive names rather than numeric positions.
Define Named Lines
.container {
display: grid;
grid-template-rows:
[header-start] 80px
[header-end content-start] 1fr
[content-end footer-start] 60px
[footer-end];
}
End at a Named Line
.content {
grid-row-start: content-start;
grid-row-end: content-end;
}
Position the Footer
.footer {
grid-row-start: footer-start;
grid-row-end: footer-end;
}
Repeated Named Lines
.container {
display: grid;
grid-template-rows:
repeat(4, [section] 80px)
[section];
}
.item {
grid-row-start: section 2;
grid-row-end: section 4;
}
The integer selects a particular occurrence of the named grid line.
Named Span
.item {
grid-row-start: section 1;
grid-row-end: span 2 section;
}
The ending boundary is found by counting forward to the second matching section line after the starting boundary.
Named Grid Areas
.container {
display: grid;
grid-template-areas:
"header"
"main"
"footer";
grid-template-rows: 80px 1fr 60px;
}
.main {
grid-row-start: main-start;
grid-row-end: main-end;
}
Named grid areas automatically establish corresponding -start and -end line names.
Important Consideration
Check named lines carefully. Missing names can produce implicit line resolution and unexpected placement.
Automatic Placement
The auto keyword allows CSS Grid to determine an item's ending boundary from its placement and sizing constraints.
Default Value
.item {
grid-row-end: auto;
}
Definite Starting Line
.item {
grid-row-start: 2;
grid-row-end: auto;
}
For a normal grid item without other span constraints, this places the item in the second row.
Automatic Starting Line
.item {
grid-row-start: auto;
grid-row-end: 4;
}
With an automatic starting boundary and a definite ending line, a normal grid item occupies one row ending at line 4.
Automatic Placement with a Span
.item {
grid-row-start: auto;
grid-row-end: span 2;
}
Grid Auto-Flow
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-flow: row;
}
The grid-auto-flow property controls how automatically placed items fill available grid cells.
Implicit Grid Rows
When an item's ending line extends beyond the explicit grid, CSS Grid can generate additional implicit rows.
Define Three Explicit Rows
.container {
display: grid;
grid-template-rows: repeat(3, 80px);
grid-auto-rows: 100px;
}
End Beyond the Explicit Grid
.item {
grid-row-start: 2;
grid-row-end: 6;
}
The explicit grid ends at line 4. Ending at line 6 requires two additional implicit rows.
Size Implicit Rows Automatically
.container {
display: grid;
grid-template-rows: repeat(3, 80px);
grid-auto-rows: minmax(80px, auto);
}
Important Consideration
The grid-row-end property controls placement, while grid-auto-rows controls the size of implicitly generated rows.
Shorthand Relationship
The grid-row-end property is one of the two longhand properties combined by the grid-row shorthand.
Separate Longhand Properties
.item {
grid-row-start: 2;
grid-row-end: 5;
}
Equivalent Shorthand
.item {
grid-row: 2 / 5;
}
Override the Ending Boundary
.item {
grid-row: 2 / 5;
grid-row-end: 4;
}
The final declaration changes only the ending boundary, leaving the starting boundary at line 2.
Shorthand Reset Behavior
.item {
grid-row-end: 5;
grid-row: 2;
}
The shorthand sets grid-row-start to 2 and resets grid-row-end to auto.
Important Consideration
Use the longhand when you need to change only the ending boundary. Use grid-row when both boundaries should be assigned together.
Responsive Layouts
Media queries can change an item's ending row line as the grid layout changes.
Default Layout
.layout {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: repeat(3, auto);
gap: 16px;
}
.layout .feature {
grid-row-start: 1;
grid-row-end: 2;
}
Larger Screens
@media (min-width: 768px) {
.layout {
grid-template-columns: 1fr 2fr;
grid-template-rows: repeat(2, auto);
}
.layout .feature {
grid-column: 1;
grid-row-start: 1;
grid-row-end: 3;
}
}
On larger screens, the featured item spans both explicitly defined rows.
Important Consideration
When a media query changes the number of grid tracks, review explicit line references to avoid unintended implicit rows.
Writing Direction
Grid rows follow the logical block axis, which depends on the container's writing mode.
Horizontal Writing Mode
.container {
display: grid;
writing-mode: horizontal-tb;
grid-template-rows: repeat(3, 80px);
}
Rows progress from top to bottom in a horizontal writing mode.
Vertical Writing Mode
.container {
display: grid;
writing-mode: vertical-rl;
grid-template-rows: repeat(3, 80px);
}
In this vertical writing mode, rows progress from right to left.
Important Consideration
The ending row line follows the grid's logical block direction. It does not always correspond to a physical bottom edge.
Inheritance
The grid-row-end property is not inherited.
Parent Grid Item
.parent-item {
grid-row-end: 4;
}
Nested Grid Item
.nested-item {
grid-row-end: auto;
}
A nested grid item does not automatically receive the ending line assigned to its parent.
Explicit Inheritance
.nested-item {
grid-row-end: inherit;
}
The inherit keyword copies the computed value from the parent, although that value is resolved within the nested item's own grid context.
Reset to the Initial Value
.item {
grid-row-end: initial;
}
Reset with unset
.item {
grid-row-end: unset;
}
Because this property is not inherited, unset resets it to auto.
grid-row-end Example
This example uses a three-column grid with three explicit rows. The featured item begins at the first row line and ends at line 4, spanning all three rows. The remaining items occupy individual cells.
HTML Example
<div class="grid-row-end-demo">
<div class="grid-item featured">Featured Item</div>
<div class="grid-item item-two">Item 2</div>
<div class="grid-item item-three">Item 3</div>
<div class="grid-item item-four">Item 4</div>
<div class="grid-item item-five">Item 5</div>
<div class="grid-item item-six">Item 6</div>
</div>
CSS Example
.grid-row-end-demo {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-template-rows: repeat(3, 70px);
gap: 12px;
}
.grid-row-end-demo .grid-item {
display: flex;
align-items: center;
justify-content: center;
padding: 8px;
background-color: #596579;
color: #ffffff;
text-align: center;
font-weight: bold;
border-radius: 4px;
}
.grid-row-end-demo .featured {
grid-column: 1;
grid-row-start: 1;
grid-row-end: 4;
background-color: #2456a6;
}
.grid-row-end-demo .item-two {
grid-column: 2;
grid-row: 1;
}
.grid-row-end-demo .item-three {
grid-column: 3;
grid-row: 1;
}
.grid-row-end-demo .item-four {
grid-column: 2;
grid-row: 2;
}
.grid-row-end-demo .item-five {
grid-column: 3;
grid-row: 2;
}
.grid-row-end-demo .item-six {
grid-column: 2 / 4;
grid-row: 3;
}
The featured item uses grid-row-end: 4 with grid-row-start: 1, so it occupies all three rows.
Changing the ending line to 3 would reduce the featured item's span to two rows. The other items retain their assigned positions.
Common Mistakes
Confusing Row Numbers with Line Numbers
An ending line of 4 identifies the boundary after row 3, not row 4 itself.
Using Zero as a Line Number
.item {
grid-row-end: 0;
}
Grid line zero is invalid. Use a positive or negative nonzero integer.
Using an Invalid Span
.item {
grid-row-end: span 0;
}
The span count must be greater than zero.
Using a Length Value
.item {
grid-row-end: 100px;
}
Lengths cannot specify grid line placement. Use grid-template-rows or grid-auto-rows for track sizing.
Using Two Span Values
.item {
grid-row-start: span 2;
grid-row-end: span 3;
}
When both row placement boundaries use span, the ending span is treated as auto.
Forgetting Shorthand Resets
A later grid-row declaration can reset an earlier grid-row-end value.
Important Considerations
Keep the following points in mind when using grid-row-end:
- The property specifies the ending boundary of a grid item's row placement.
- It works with
grid-row-startto determine the occupied rows. - Grid line numbers refer to boundaries, not row tracks.
- The
spankeyword specifies how many rows an item spans. - Negative line numbers count from the end of the explicit grid.
- Named grid lines can make layouts easier to maintain.
- Placement beyond the explicit grid may create implicit rows.
- The
grid-rowshorthand can override this longhand property. - The property controls placement, not row height.
- Visual placement does not change document or keyboard navigation order.
Browser Support
The CSS grid-row-end property is widely available in modern browsers that support CSS Grid Layout, including Chrome, Edge, Firefox, Safari, and Opera.
For current browser compatibility information, visit Can I Use? and search for grid-row-end.
Specifications
The grid-row-end property is defined in the CSS Grid Layout specification.
CSS Grid Layout Module Level 1: grid-row-end
The specification defines grid line placement, named lines, spans, and the relationship between the row placement longhand properties.
CSS Grid Layout Module Level 2
For additional documentation and examples, consult MDN Web Docs.
