CSS grid-row Property

The CSS grid-row property is a shorthand that specifies the starting and ending row lines of a grid item.

It combines grid-row-start and grid-row-end into one declaration. You can position items using numbered grid lines, named lines, the span keyword, or automatic placement.

grid-row Syntax

The grid-row property accepts one or two grid line positions, separated by a forward slash when both boundaries are provided.

Basic Syntax

selector {
  grid-row: auto;
}

Starting and Ending Lines

.item {
  grid-row: 2 / 4;
}

Starting Line Only

.item {
  grid-row: 2;
}

Start Line with Span

.item {
  grid-row: 2 / span 3;
}

Span with Ending Line

.item {
  grid-row: span 2 / 5;
}

Named Grid Lines

.item {
  grid-row: content-start / content-end;
}

Negative Grid Lines

.item {
  grid-row: 1 / -1;
}

Automatic Placement

.item {
  grid-row: auto;
}

CSS-Wide Keywords

.item {
  grid-row: initial;
}
.item {
  grid-row: inherit;
}
.item {
  grid-row: unset;
}
.item {
  grid-row: revert;
}
.item {
  grid-row: revert-layer;
}

Grid line numbers cannot be zero, and a span count must be a positive integer. Physical lengths such as 100px and percentages are not valid placement values.

Property Values

The grid-row property accepts the following grid placement values.

Value Description
auto Allows automatic placement or an automatic span.
<integer> References 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> Identifies a particular occurrence of a named grid line.
span <integer> Specifies how many row tracks an item spans.
span <custom-ident> Uses a named grid line to determine the span boundary.
<start> / <end> Sets the starting and ending row boundaries.
initial Resets both longhand properties to auto.
inherit Inherits both computed longhand values from the parent.
unset Resets both non-inherited longhand properties to their initial values.
revert Reverts both longhand properties according to cascade origin rules.
revert-layer Reverts both longhand properties according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto for both longhands
Inherited No
Applies to Grid items and absolutely positioned boxes whose containing block is a grid container
Computed value As specified for each longhand
Animation type Discrete
Percentages Not applicable
Longhand properties grid-row-start and grid-row-end

The grid-row property controls placement rather than row height. Use grid-template-rows or grid-auto-rows to control track sizing.

How It Works

The grid-row shorthand determines the row boundaries occupied by an item inside a CSS Grid container.

Create a Grid Container

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 80px);
  gap: 12px;
}

Place an Item in the Second Row

.item {
  grid-row: 2 / 3;
}

The item begins at row line 2 and ends at line 3, occupying one row.

Span Multiple Rows

.item {
  grid-row: 2 / 5;
}

The item occupies rows 2, 3, and 4.

Equivalent Longhand Properties

.item {
  grid-row-start: 2;
  grid-row-end: 5;
}

Important Consideration

The starting and ending lines define an item's row area. The actual height depends on the sizes of the grid tracks it occupies.

Grid Row Lines

Grid lines separate the rows in a grid. A grid with four explicitly defined rows has five row boundary lines.

Four Explicit Rows

.container {
  display: grid;
  grid-template-rows: repeat(4, 80px);
}

First Row

.item {
  grid-row: 1 / 2;
}

Second Row

.item {
  grid-row: 2 / 3;
}

Third and Fourth Rows

.item {
  grid-row: 3 / 5;
}

Grid Row Reference

grid-row Value Rows Occupied
1 / 2 Row 1
2 / 3 Row 2
2 / 4 Rows 2 and 3
1 / 5 All four rows

The ending line identifies the boundary after the final occupied row, not an additional row.

Spanning Rows

The span keyword specifies the number of row tracks an item should occupy.

Span Two Rows

.item {
  grid-row: 1 / span 2;
}

Span Three Rows

.item {
  grid-row: 2 / span 3;
}

Count Backward from an Ending Line

.item {
  grid-row: span 2 / 5;
}

The item occupies the two rows immediately before line 5.

Use an Automatic Starting Position

.item {
  grid-row: auto / span 2;
}

The placement algorithm chooses the starting position while preserving a two-row span.

Important Consideration

A span count must be greater than zero. Spanning beyond the explicit grid may create implicit rows.

Negative Line Numbers

Negative grid line numbers count backward from the end of the explicit grid.

Last Explicit Row

.item {
  grid-row: -2 / -1;
}

Last Two Explicit Rows

.item {
  grid-row: -3 / -1;
}

All Explicit Rows

.item {
  grid-row: 1 / -1;
}

In a four-row explicit grid, -1 refers to line 5, the ending boundary of the explicit grid.

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 row placement.

Define Named Rows

.container {
  display: grid;
  grid-template-rows:
    [header-start] 80px
    [header-end content-start] 1fr
    [content-end footer-start] 60px
    [footer-end];
}

Position the Content

.content {
  grid-row: content-start / content-end;
}

Position the Footer

.footer {
  grid-row: footer-start / footer-end;
}

Repeated Named Lines

.container {
  display: grid;
  grid-template-rows:
    repeat(4, [section] 80px)
    [section];
}
.item {
  grid-row: section 2 / section 4;
}

The integer selects a particular occurrence of the named line.

Named Grid Areas

.container {
  display: grid;
  grid-template-areas:
    "header"
    "main"
    "footer";
  grid-template-rows: 80px 1fr 60px;
}
.main {
  grid-row: main-start / main-end;
}

Named grid areas automatically establish corresponding -start and -end line names.

Important Consideration

Use consistent line names. A missing name can produce unexpected placement through implicit named-line resolution.

Automatic Placement

The auto keyword allows the CSS Grid placement algorithm to determine row positioning.

Default Placement

.item {
  grid-row: auto;
}

Automatic Starting Position

.item {
  grid-row: auto / span 2;
}

Definite Starting Position

.item {
  grid-row: 3 / auto;
}

With an automatic ending boundary and no additional span constraint, a normal grid item occupies one row.

Row Auto-Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row;
}

Column Auto-Placement

.container {
  display: grid;
  grid-template-rows: repeat(3, 80px);
  grid-auto-flow: column;
}

Dense Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row dense;
}

Dense placement can fill earlier available spaces with later items when their spans fit.

Important Consideration

Automatic placement depends on track definitions, item spans, other placement constraints, and the grid-auto-flow setting.

Implicit Grid Rows

Positioning an item outside the explicit grid can cause CSS Grid to generate additional implicit rows.

Define Three Rows

.container {
  display: grid;
  grid-template-rows: repeat(3, 80px);
  grid-auto-rows: 100px;
}

Place an Item Beyond the Grid

.item {
  grid-row: 5 / 7;
}

The explicit grid ends at line 4. Placing an 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 property determines placement. The grid-auto-rows property controls the sizing of implicitly generated rows.

Shorthand Behavior

The grid-row shorthand sets both grid-row-start and grid-row-end.

Separate Longhand Properties

.item {
  grid-row-start: 2;
  grid-row-end: 5;
}

Equivalent Shorthand

.item {
  grid-row: 2 / 5;
}

Single Number

.item {
  grid-row: 2;
}

This sets grid-row-start to 2 and grid-row-end to auto.

Single Named Line

.item {
  grid-row: content;
}

When a single custom identifier is provided, both longhands receive that identifier. Each boundary is resolved using its corresponding named grid line.

Shorthand Reset Behavior

.item {
  grid-row-start: 2;
  grid-row-end: 5;
  grid-row: 3;
}

The final shorthand changes the starting boundary to line 3 and resets the ending boundary to auto.

Override a Single Boundary

.item {
  grid-row: 2 / 5;
  grid-row-end: 4;
}

The final declaration changes only the ending boundary.

Important Consideration

Use the shorthand when both boundaries should be set together. Use the longhand properties when only one boundary needs to change.

Responsive Layouts

Grid row placement can change across viewport sizes to support different layouts.

Single-Column Layout

.page-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.page-layout .header {
  grid-row: 1;
}
.page-layout .main {
  grid-row: 2;
}
.page-layout .sidebar {
  grid-row: 3;
}

Desktop 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: 1;
  }
  .page-layout .sidebar {
    grid-column: 1;
    grid-row: 2;
  }
  .page-layout .main {
    grid-column: 2;
    grid-row: 2;
  }
}

At smaller widths, the content appears in separate rows. At larger widths, the sidebar and main content share the second row.

Important Consideration

Review row placement whenever a media query changes the grid structure. Explicit positions can create additional rows if they fall outside the intended grid.

Overlapping Grid Items

Grid items can overlap when their assigned row and column areas intersect.

First Item

.item-one {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}

Second Item

.item-two {
  grid-column: 2 / 4;
  grid-row: 2 / 4;
}

Both items occupy part of the second row and second column.

Control Stacking Order

.item-two {
  z-index: 2;
}

Grid items can use z-index to control stacking order without requiring a non-static position value.

Important Consideration

Overlapping items remain in their original document order. Ensure important content remains readable and accessible.

Writing Direction

Grid rows follow the logical block axis of the grid container.

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, the block axis progresses from right to left, so the grid rows follow that direction.

Important Consideration

Grid row line numbers follow logical block direction. Row line 1 does not always represent the physical top edge of a grid.

Inheritance

The grid-row property is not inherited.

Parent Grid Item

.parent-item {
  grid-row: 2 / 4;
}

Nested Grid Item

.nested-item {
  grid-row: auto;
}

A nested grid item does not automatically receive the row placement assigned to its parent.

Explicit Inheritance

.nested-item {
  grid-row: inherit;
}

The inherit keyword copies the computed values of both longhand properties from the parent.

Reset to Initial Values

.item {
  grid-row: initial;
}

Reset with unset

.item {
  grid-row: unset;
}

Because the longhand properties are not inherited, unset resets both to auto.

Important Consideration

Inherited grid line values are resolved within the receiving item's grid context. They do not automatically reference the parent's original grid tracks.

grid-row Example

This example demonstrates a three-column grid with four explicit rows. The featured item spans the first three rows, while the remaining items occupy individual grid cells.

HTML Example

<div class="grid-row-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-demo {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, 70px);
  gap: 12px;
}
.grid-row-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-demo .featured {
  grid-column: 1;
  grid-row: 1 / 4;
  background-color: #2456a6;
}
.grid-row-demo .item-two {
  grid-column: 2;
  grid-row: 1;
}
.grid-row-demo .item-three {
  grid-column: 3;
  grid-row: 1;
}
.grid-row-demo .item-four {
  grid-column: 2;
  grid-row: 2;
}
.grid-row-demo .item-five {
  grid-column: 3;
  grid-row: 2;
}
.grid-row-demo .item-six {
  grid-column: 2 / 4;
  grid-row: 3;
}
Browser Result
Item 2
Item 3
Item 4
Item 5
Item 6

The featured item uses grid-row: 1 / 4, spanning the first three rows. Its column placement is set separately with grid-column: 1.

Item 6 uses grid-row: 3, placing it in the third row, while grid-column: 2 / 4 makes it span the remaining two columns.

Changing the featured item's value to grid-row: 1 / 3 would reduce its span to two rows.

Common Mistakes

Using Row Numbers Instead of Grid Lines

The value grid-row: 2 / 4 occupies two rows, not three. The ending number identifies a boundary line.

Using Zero as a Line Number

.item {
  grid-row: 0 / 3;
}

Grid line zero is invalid. Use positive or negative nonzero integers.

Using an Invalid Span

.item {
  grid-row: 1 / span 0;
}

A span count must be a positive integer.

Using Length Values

.item {
  grid-row: 100px / 200px;
}

Lengths do not identify grid placement lines. Use grid-template-rows to define row sizes.

Forgetting Shorthand Resets

A new grid-row declaration resets both row placement longhands, including any omitted boundary.

Confusing Explicit and Implicit Rows

Negative line numbers count from the explicit grid's ending boundary, not from the last implicit row.

Important Considerations

Keep the following points in mind when using grid-row:

  • The property controls placement, not row sizing.
  • The shorthand sets both grid-row-start and grid-row-end.
  • A single numeric value sets the starting line and leaves the ending boundary automatic.
  • A single named line value is assigned to both longhands.
  • The span keyword defines the number of row tracks an item occupies.
  • Negative numbers count from the end of the explicit grid.
  • Placement beyond explicit grid boundaries can create implicit rows.
  • Explicit placement can cause grid items to overlap.
  • Grid row numbering follows the logical block axis.
  • Visual placement does not change document order or keyboard navigation order.

Browser Support

The CSS grid-row 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.

Specifications

The grid-row property is defined in the CSS Grid Layout specification.

CSS Grid Layout Module Level 1: grid-row

The specification defines the shorthand, its longhand properties, grid line placement, spans, and automatic placement behavior.

CSS Grid Layout Module Level 2

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: grid-row