CSS grid-row-start Property
The CSS grid-row-start property specifies the starting grid line of a grid item along the row axis.
It works with grid-row-end to determine which rows an item occupies. You can position items using numbered lines, named lines, the span keyword, or automatic placement. The property is also a longhand component of the grid-row shorthand.
grid-row-start Syntax
The grid-row-start property accepts a grid line position, a span, or the auto keyword.
Basic Syntax
selector {
grid-row-start: auto;
}
Numbered Grid Line
.item {
grid-row-start: 2;
}
Negative Grid Line
.item {
grid-row-start: -2;
}
Named Grid Line
.item {
grid-row-start: content-start;
}
Span a Number of Rows
.item {
grid-row-start: span 2;
}
Span to a Named Line
.item {
grid-row-start: span section;
}
Automatic Starting Line
.item {
grid-row-start: auto;
}
CSS-Wide Keywords
.item {
grid-row-start: initial;
}
.item {
grid-row-start: inherit;
}
.item {
grid-row-start: unset;
}
.item {
grid-row-start: revert;
}
.item {
grid-row-start: revert-layer;
}
Grid line numbers cannot be zero, and a span count must be a positive integer. Lengths and percentages are not valid placement values.
Property Values
The grid-row-start property supports the following values.
| Value | Description |
|---|---|
auto |
Allows automatic placement or an automatic span. |
<integer> |
Specifies a numbered grid line. Negative integers count backward from the end of the explicit grid. |
<custom-ident> |
References a named grid line. |
<integer> <custom-ident> |
Selects a particular occurrence of a named grid line. |
span <integer> |
Specifies how many row tracks the item spans backward from its ending boundary. |
span <custom-ident> |
Uses a named grid line to determine the starting boundary relative to the ending boundary. |
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 controls the starting boundary of a grid item's placement, not the height of its rows.
How It Works
CSS Grid uses grid-row-start and grid-row-end to determine the row tracks 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;
}
Start at the Second Row Line
.item {
grid-row-start: 2;
grid-row-end: 4;
}
The item begins at line 2 and ends at line 4, occupying the second and third rows.
Change the Starting Line
.item {
grid-row-start: 1;
grid-row-end: 4;
}
Changing the starting line to 1 extends the item upward to include the first row.
Important Consideration
The starting line identifies the boundary before the first occupied row. It does not represent a row's height or a pixel position.
Grid Line Numbering
Grid lines separate the tracks in a CSS Grid container. Four explicitly defined rows create five row boundary lines.
Define Four Rows
.container {
display: grid;
grid-template-rows: repeat(4, 80px);
}
Begin at the First Row
.item {
grid-row-start: 1;
grid-row-end: 3;
}
The item occupies rows 1 and 2.
Begin at the Second Row
.item {
grid-row-start: 2;
grid-row-end: 4;
}
The item occupies rows 2 and 3.
Begin at the Third Row
.item {
grid-row-start: 3;
grid-row-end: 5;
}
The item occupies rows 3 and 4.
| Starting Line | Rows Occupied When Ending at Line 5 |
|---|---|
1 |
Rows 1 through 4 |
2 |
Rows 2 through 4 |
3 |
Rows 3 and 4 |
4 |
Row 4 |
The number of occupied rows depends on both the starting and ending boundaries.
Spanning Rows
The span keyword can define the starting boundary by counting backward from a definite ending line.
Span Two Rows Backward
.item {
grid-row-start: span 2;
grid-row-end: 5;
}
The item occupies rows 3 and 4, beginning at line 3 and ending at line 5.
Span Three Rows Backward
.item {
grid-row-start: span 3;
grid-row-end: 5;
}
The item begins at line 2 and occupies three rows.
Equivalent Numbered Starting Line
.item {
grid-row-start: 2;
grid-row-end: 5;
}
Automatic Ending Position
.item {
grid-row-start: span 2;
grid-row-end: auto;
}
The automatic placement algorithm selects a suitable position while maintaining a two-row span.
Important Consideration
The span count must be a positive integer. When span is used on the starting boundary, it counts backward from the ending boundary.
Negative Line Numbers
Negative grid line numbers count backward from the end of the explicit grid.
Start at the Last Explicit Row
.item {
grid-row-start: -2;
grid-row-end: -1;
}
Start Two Rows Before the End
.item {
grid-row-start: -3;
grid-row-end: -1;
}
Start at the First Explicit Line
.item {
grid-row-start: 1;
grid-row-end: -1;
}
For a grid with four explicit rows, -1 refers to line 5, -2 refers to line 4, and -3 refers to line 3.
Important Consideration
Negative line numbers reference the explicit grid, not the last implicitly generated row.
Named Grid Lines
Named grid lines provide descriptive references for starting positions, making layouts easier to understand and maintain.
Define Named Row Lines
.container {
display: grid;
grid-template-rows:
[header-start] 80px
[header-end content-start] 1fr
[content-end footer-start] 60px
[footer-end];
}
Start at the Content Line
.content {
grid-row-start: content-start;
grid-row-end: content-end;
}
Start at the Footer Line
.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 identifies a particular occurrence of the named grid line.
Named Span
.item {
grid-row-start: span 2 section;
grid-row-end: section 4;
}
The starting boundary is determined by counting backward to the second matching section line before the ending 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 grid line names.
Important Consideration
Use consistent names. A missing named line can lead to unexpected placement through implicit named-line resolution.
Automatic Placement
The auto keyword allows the CSS Grid placement algorithm to determine an item's starting boundary.
Default Starting Position
.item {
grid-row-start: auto;
}
Automatic Start with a Definite End
.item {
grid-row-start: auto;
grid-row-end: 4;
}
For a normal grid item without additional span constraints, this occupies one row ending at line 4.
Definite Start with an Automatic End
.item {
grid-row-start: 2;
grid-row-end: auto;
}
The item starts at line 2 and normally occupies one row.
Automatic Placement with a Span
.item {
grid-row-start: span 2;
grid-row-end: auto;
}
Control Automatic Placement
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-flow: row;
}
The grid-auto-flow property controls how automatically positioned grid items fill available tracks.
Implicit Grid Rows
Placing an item outside the explicitly defined grid can create additional implicit rows.
Define Three Explicit Rows
.container {
display: grid;
grid-template-rows: repeat(3, 80px);
grid-auto-rows: 100px;
}
Start Beyond the Explicit Grid
.item {
grid-row-start: 5;
grid-row-end: 7;
}
The explicit grid ends at line 4. Placing the item between lines 5 and 7 requires additional implicit rows.
Automatically Size Implicit Rows
.container {
display: grid;
grid-template-rows: repeat(3, 80px);
grid-auto-rows: minmax(80px, auto);
}
Important Consideration
The grid-row-start property determines placement. The grid-auto-rows property determines the sizes of implicit rows.
Shorthand Relationship
The grid-row-start 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 Starting Boundary
.item {
grid-row: 2 / 5;
grid-row-start: 3;
}
The final declaration changes the starting boundary to line 3 while preserving the ending boundary at line 5.
Shorthand Reset Behavior
.item {
grid-row-start: 3;
grid-row: 2 / 5;
}
The shorthand overrides the earlier starting line, setting it to line 2.
Single-Value Shorthand
.item {
grid-row: 2;
}
This sets grid-row-start to 2 and grid-row-end to auto.
Important Consideration
Use the longhand when changing only the starting boundary. Use the shorthand when setting both boundaries together.
Responsive Layouts
Media queries can change starting row positions to accommodate different grid layouts.
Default Single-Column Layout
.page-layout {
display: grid;
grid-template-columns: 1fr;
gap: 16px;
}
.page-layout .header {
grid-row-start: 1;
}
.page-layout .main {
grid-row-start: 2;
}
.page-layout .sidebar {
grid-row-start: 3;
}
Larger Screen Layout
@media (min-width: 768px) {
.page-layout {
grid-template-columns: 220px minmax(0, 1fr);
grid-template-rows: auto 1fr;
}
.page-layout .header {
grid-column: 1 / -1;
grid-row-start: 1;
}
.page-layout .sidebar {
grid-column: 1;
grid-row-start: 2;
}
.page-layout .main {
grid-column: 2;
grid-row-start: 2;
}
}
At smaller widths, the content occupies separate rows. At larger widths, the sidebar and main content begin on the same row in different columns.
Important Consideration
Review explicit line references when changing the number of grid tracks. Placement values can create unintended implicit rows if they no longer match the layout.
Writing Direction
Grid rows follow the logical block axis of the grid container, which depends on its writing mode.
Horizontal Writing Mode
.container {
display: grid;
writing-mode: horizontal-tb;
grid-template-rows: repeat(3, 80px);
}
In a horizontal writing mode, rows progress vertically from top to bottom.
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 starting row line follows the logical block direction. It does not always represent the physical top edge of the grid.
Inheritance
The grid-row-start property is not inherited.
Parent Grid Item
.parent-item {
grid-row-start: 2;
}
Nested Grid Item
.nested-item {
grid-row-start: auto;
}
A nested grid item does not automatically receive its parent's starting line.
Explicit Inheritance
.nested-item {
grid-row-start: inherit;
}
The inherit keyword copies the computed value from the parent. That value is resolved in the receiving item's grid context.
Reset to the Initial Value
.item {
grid-row-start: initial;
}
Reset with unset
.item {
grid-row-start: unset;
}
Because this property is not inherited, unset resets it to auto.
grid-row-start Example
This example demonstrates a three-column grid with three explicit rows. The featured item begins at row line 1 and ends at line 4, spanning all three rows. The remaining items occupy individual cells.
HTML Example
<div class="grid-row-start-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-start-demo {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-template-rows: repeat(3, 70px);
gap: 12px;
}
.grid-row-start-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-start-demo .featured {
grid-column: 1;
grid-row-start: 1;
grid-row-end: 4;
background-color: #2456a6;
}
.grid-row-start-demo .item-two {
grid-column: 2;
grid-row: 1;
}
.grid-row-start-demo .item-three {
grid-column: 3;
grid-row: 1;
}
.grid-row-start-demo .item-four {
grid-column: 2;
grid-row: 2;
}
.grid-row-start-demo .item-five {
grid-column: 3;
grid-row: 2;
}
.grid-row-start-demo .item-six {
grid-column: 2 / 4;
grid-row: 3;
}
The featured item uses grid-row-start: 1 and grid-row-end: 4, occupying all three rows.
Changing grid-row-start to 2 moves the featured item's starting boundary down to the second row while keeping its ending boundary at line 4.
The remaining items retain their assigned positions, although they may overlap the featured item if their grid areas intersect.
Common Mistakes
Confusing Row Numbers with Grid Lines
The value grid-row-start: 2 refers to the boundary before the second row, not the height or number of rows occupied.
Using Zero as a Grid Line
.item {
grid-row-start: 0;
}
Grid line zero is invalid. Use positive or negative nonzero integers.
Using an Invalid Span
.item {
grid-row-start: span 0;
}
The span count must be greater than zero.
Using a Length Value
.item {
grid-row-start: 100px;
}
Lengths cannot specify grid line placement. Use grid-template-rows or grid-auto-rows to control row sizes.
Using Span on Both Boundaries
.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. Avoid this combination when you need two definite boundaries.
Forgetting Shorthand Overrides
A later grid-row declaration can override an earlier grid-row-start value.
Confusing Explicit and Implicit Rows
Negative line numbers count from the explicit grid, not from the last implicit row.
Important Considerations
Keep the following points in mind when using grid-row-start:
- The property specifies the starting boundary of a grid item's row placement.
- It works with
grid-row-endto determine the occupied rows. - Grid line numbers identify boundaries, not row tracks.
- A starting value of
span 2counts backward from the ending boundary when that boundary is definite. - Negative line numbers count from the end of the explicit grid.
- Named grid lines provide descriptive placement references.
- Placement beyond the explicit grid can create implicit rows.
- The
grid-rowshorthand can override this longhand property. - The property controls placement rather than row height.
- Visual placement does not change document order or keyboard navigation order.
Browser Support
The CSS grid-row-start 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-start.
Specifications
The grid-row-start property is defined in the CSS Grid Layout specification.
CSS Grid Layout Module Level 1: grid-row-start
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.
