🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Grid-row

AI & DATA SCIENCE // grid-row

The grid-row property places a grid item into specific row lines, controlling both which row it starts in and how many rows it spans, working identically to grid-column but along the vertical axis.

Syntax

grid-row: start-line / end-line;
grid-row: start-line / span number;

Deep Dive Course

Just like grid-column, grid-row uses numbered grid lines along the vertical axis, starting at 1, with a value like grid-row: 1 / 3 placing an item starting at row line 1 and spanning down to row line 3, covering the two row tracks in between. The span keyword works identically too, grid-row: 2 / span 2 starting an item at row line 2 and having it span downward across 2 row tracks — combining grid-column and grid-row together on the same item is how a specific grid item gets placed into an exact rectangular region spanning both a specific column range and a specific row range simultaneously.

1Understanding Grid-row

Just like grid-column, grid-row uses numbered grid lines along the vertical axis, starting at 1, with a value like grid-row: 1 / 3 placing an item starting at row line 1 and spanning down to row line 3, covering the two row tracks in between. The span keyword works identically too, grid-row: 2 / span 2 starting an item at row line 2 and having it span downward across 2 row tracks — combining grid-column and grid-row together on the same item is how a specific grid item gets placed into an exact rectangular region spanning both a specific column range and a specific row range simultaneously.

💡

Combine grid-column and grid-row together on the same item, rather than relying on just one of them alone, whenever an item needs to span a specific rectangular region across both axes simultaneously, like a large featured item spanning both multiple columns and multiple rows.

editor.html
.featured {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}
localhost:3000

2Practical Example

Here is a real-world application of Grid-row showing how it is used in production CSS code.

editor.html
.sidebar {
  grid-row: 1 / span 3;
}
localhost:3000

3Best Practices

Follow these guidelines when working with Grid-row:

1. Use grid-row alongside grid-column together for precise two-dimensional placement of an item into a specific rectangular region of the grid

2. Use grid-row: start / span number for spanning a specific number of rows starting from a given line, mirroring grid-column's own span syntax

3. Remember row lines are numbered the same way as column lines, starting from 1, with the numbers referring to the lines between tracks, not the tracks themselves

⚠️

Tip: Combine grid-column and grid-row together on the same item, rather than relying on just one of them alone, whenever an item needs to span a specific rectangular region across both axes simultaneously, like a large featured item spanning both multiple columns and multiple rows.

editor.html
.featured {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}
localhost:3000

Examples

Example 01Basic Usage
.featured {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}
Example 02Advanced Example
.sidebar {
  grid-row: 1 / span 3;
}

Best Practices

  • Use grid-row alongside grid-column together for precise two-dimensional placement of an item into a specific rectangular region of the grid
  • Use grid-row: start / span number for spanning a specific number of rows starting from a given line, mirroring grid-column's own span syntax
  • Remember row lines are numbered the same way as column lines, starting from 1, with the numbers referring to the lines between tracks, not the tracks themselves

Interview Question

Why is combining both grid-column and grid-row on the same item necessary to place it into a specific rectangular region, rather than either property alone being sufficient?

Hint: Think about what each individual property, on its own, actually controls — one specific axis, or both dimensions of the grid simultaneously.

grid-column exclusively controls an item's placement and span along the horizontal axis, which column lines it starts and ends at, and has no defined effect whatsoever on which rows that item occupies, while grid-row exclusively controls placement along the vertical axis in exactly the same one-dimensional way, with no effect on which columns are involved. Since a genuinely rectangular region on a two-dimensional grid is inherently defined by both a specific horizontal range and a specific vertical range simultaneously, controlling only one of these two independent axes leaves the other axis's placement to whatever default, automatic placement behavior the grid would otherwise apply, which usually isn't the specific, intentional row or column range actually needed for that particular rectangular region. Only by explicitly specifying both grid-column, defining the horizontal extent, and grid-row, defining the vertical extent, together on the same item can you fully and precisely pin down both dimensions of exactly which rectangular block of grid cells that item should actually occupy.

Exercises

MediumPractice using Grid-row in a real scenario.
View Solution
.featured {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
}

Frequently Asked Questions

Why is combining both grid-column and grid-row on the same item necessary to place it into a specific rectangular region, rather than either property alone being sufficient?

grid-column exclusively controls an item's placement and span along the horizontal axis, which column lines it starts and ends at, and has no defined effect whatsoever on which rows that item occupies, while grid-row exclusively controls placement along the vertical axis in exactly the same one-dimensional way, with no effect on which columns are involved. Since a genuinely rectangular region on a two-dimensional grid is inherently defined by both a specific horizontal range and a specific vertical range simultaneously, controlling only one of these two independent axes leaves the other axis's placement to whatever default, automatic placement behavior the grid would otherwise apply, which usually isn't the specific, intentional row or column range actually needed for that particular rectangular region. Only by explicitly specifying both grid-column, defining the horizontal extent, and grid-row, defining the vertical extent, together on the same item can you fully and precisely pin down both dimensions of exactly which rectangular block of grid cells that item should actually occupy.

Related Functions

Grid-columnGrid-template-rowsGrid-template-areas