CSS grid-row Property Tutorial

In this section, we will learn what the grid-row property is and how to use it in CSS.

Click here to run the example of grid-row property.

CSS grid-row Property Definition and Usage

After we’ve created our CSS grid, by default, grid-items will be automatically positioned on each cell of the grid. But this is the default behavior and we can decide where on the grid we want each grid-item to be positioned.

So in order to do this, we need 2 properties.

  • grid-column: Using this property, we can declare the number of grid’s columns that the target grid-item should expand on.
  • grid-row: Using this property, we can declare the number of grid’s rows that the target grid-item should expand on.

This section is about `grid-row` and you can learn about `grid-column` in its section.

You should know that the `grid-row` is the shorthand property of two other properties:

  • grid-row-start: Using this property, we can declare the line number or line name that the top edge of the target item should be placed on.
  • grid-row-end: Using this property, we can declare the line number or line name that the bottom edge of the target item should be placed on.

CSS grid-row Property Syntax

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

grid-row: start-row-line-name / end-row-line-name;

CSS grid-row Property Value

  • start-row-line-number: We know that a grid has multiple horizontal lines, so using this value, we can determine what line number the top edge of the target item should be placed on.
  • end-row-line-number: Using this value, we can determine what line number the bottom edge of the target item should be placed on.
  • start-row-line-name: As explained in `grid-template-rows` section, when creating a grid, we can actually name the lines of that grid. So “start-row-line-name” is actually the name of the grid’s line we want the top edge of the target item to be placed on.
  • end-row-line-name: this value is actually the name of the grid’s line we want the bottom edge of the target item be placed on.

Note: We use forward slash “/” in order to separate the values of top and bottom line numbers/ names.

Also, there’s a keyword named “span” which can be used as the value of this property. Here’s the syntax:

grid-row: span number-of-tracks;

  • span: this is the keyword and that means a number of tracks.
  • Number-of-track: this is the number of tracks we want the grid-item to expand on.

Example= grid-row: span 3; // means expand the target item in 3 rows.

Example: grid-row property in CSS

See the Pen grid-row property in CSS by Omid Dehghan (@enjoytutorials1) on CodePen.

Leave a Reply