CSS grid-row-gap Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The grid-row-gap property controls the vertical space between rows in a CSS grid layout.

01

Row gap

Vertical.

02

0 default

No space.

03

px / rem

Length units.

04

Container

Grid parent.

05

row-gap

Modern alias.

06

Between only

Not edges.

Introduction

The grid-row-gap property in CSS is used to set the size of the gap (gutter) between rows in a grid layout. This property is essential for creating space between grid items, making the layout more readable and visually appealing.

Definition and Usage

Set grid-row-gap on a grid container with display: grid. It adds space only between row tracks, not on the outer top or bottom edges of the grid. While grid-row-gap has been superseded by the row-gap property in modern CSS, it is still widely supported and useful when reading older codebases.

💡
Beginner Tip

Use grid-row-gap when you want vertical spacing only. If you need both row and column spacing, use the gap shorthand instead.

📝 Syntax

The syntax for the grid-row-gap property is simple. You can specify the gap size using any valid CSS length unit, such as px, em, %, or rem:

syntax.css
.container {
  grid-row-gap: length;
}

Here, length can be a fixed size (e.g., 20px), a relative size (e.g., 1em), or a percentage.

Basic Example

grid-row-gap-basic.css
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-row-gap: 20px;
}
grid-row-gap: 20px; grid-row-gap: 1.5rem; row-gap: 24px;

Default Value

The default value of the grid-row-gap property is 0, meaning there is no gap between the rows unless explicitly set.

Syntax Rules

  • Applies to grid containers only, not individual grid items.
  • Accepts length and percentage values.
  • Legacy alias of row-gap in grid layouts.
  • The property is not inherited.
  • Gap appears only between rows, not on the container edges.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toGrid containers
InheritedNo
ControlsVertical gap between rows
Modern equivalentrow-gap

💎 Property Values

ValueDescription
lengthA fixed or relative length value, such as 10px, 1em, 2rem, etc.
percentageA percentage value relative to the size of the grid container

👀 Live Preview

Six items in three columns with grid-row-gap: 1rem between rows:

1
2
3
4
5
6

Examples Gallery

Add 20 pixels of row gap, compare with no gap, try rem units, and combine with column gap for asymmetric spacing.

🔢 Row Spacing

Start with the reference example — a three-column grid with 20px row gap.

Example 1 — 20px Row Gap

Create a simple grid with a row gap of 20 pixels between each row of items.

grid-row-gap-20px.css
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-row-gap: 20px;
}
Try It Yourself

How It Works

Each row track stays the same height, but 20px of empty space appears between adjacent rows.

Example 2 — No Gap vs Row Gap

See how row gap improves readability compared to rows touching each other.

grid-row-gap-compare.css
.no-gap { grid-row-gap: 0; }
.with-gap { grid-row-gap: 24px; }
Try It Yourself

How It Works

Without gap, rows sit flush together. Adding grid-row-gap creates breathing room between items vertically.

📈 Spacing Patterns

Use relative units and combine with column gap for flexible layouts.

Example 3 — rem for Scalable Gap

Use rem units so row gap scales with root font size.

grid-row-gap-rem.css
.grid-container {
  grid-template-columns: repeat(2, 1fr);
  grid-row-gap: 1.5rem;
}
Try It Yourself

How It Works

1.5rem gap grows or shrinks when the user changes their default font size, keeping spacing accessible.

Example 4 — Row Gap with Column Gap

Set row and column spacing independently for a card grid.

grid-row-gap-asymmetric.css
.card-grid {
  grid-row-gap: 24px;
  grid-column-gap: 12px;
}
Try It Yourself

How It Works

Wider row gap and tighter column gap create a layout that reads clearly down the page while keeping horizontal spacing compact.

♿ Accessibility

  • Use adequate gap so clickable items are not too close together on touch screens.
  • Prefer rem units so spacing scales with user font preferences.
  • Do not rely on gap alone for visual grouping; use headings and landmarks.
  • Test zoom levels to ensure gaps remain readable at 200% zoom.
  • Keep contrast between items and background clear even with spacing.

🧠 How grid-row-gap Works

1

Grid rows are defined

grid-template-rows or auto-placement creates row tracks.

Template
2

grid-row-gap is set

You choose the vertical space between adjacent rows.

Gap
3

Browser inserts gutters

Empty space appears between row tracks, not on the outer top or bottom edges.

Spacing
=

Cleaner row layout

Items stay aligned with consistent vertical spacing between them.

🖥 Browser Compatibility

The grid-row-gap property is supported in most modern browsers, including recent versions of Chrome, Firefox, Safari, Edge, and Opera. For future-proofing, consider using row-gap in new code.

Baseline · Modern browsers

grid-row-gap everywhere

Row gap in grid layouts works in all major modern browsers.

97% Modern browser support
Google Chrome 57+ · Desktop & Mobile
Full support
Mozilla Firefox 52+ · Desktop & Mobile
Full support
Apple Safari 10.1+ · macOS & iOS
Full support
Microsoft Edge 16+ · 79+ Chromium
Full support
Opera 44+
Full support
grid-row-gap property 97% supported

Bottom line: Safe for modern projects. Prefer row-gap in new code; both work in grid layouts.

🎉 Conclusion

The grid-row-gap property is a useful tool for creating space between rows in a CSS grid layout. Although it has been replaced by the row-gap property in modern CSS, understanding how to use grid-row-gap is still beneficial, especially when working with older codebases.

Experiment with different gap sizes to see how they can improve the layout and readability of your grid designs. For new code, consider using row-gap or the gap shorthand alongside this legacy property name.

💡 Best Practices

✅ Do

  • Set gap on the grid container
  • Use rem for accessible scaling
  • Pair with grid-column-gap when axes differ
  • Prefer gap when both axes match
  • Test touch targets with adequate spacing

❌ Don’t

  • Apply on grid items instead of containers
  • Use margins when gap solves spacing cleanly
  • Expect gap on container outer edges
  • Use tiny gaps on mobile touch layouts
  • Forget the modern row-gap alias

Key Takeaways

Knowledge Unlocked

Five things to remember about grid-row-gap

Use these points when spacing grid rows.

5
Core concepts
0 02

Default 0

No space.

Default
20px 03

Length

px or rem.

Syntax
between 04

Between only

Not edges.

Behavior
row 05

row-gap

Modern name.

Alias

❓ Frequently Asked Questions

grid-row-gap sets the vertical space between rows in a CSS grid container.
The default value is 0, which means there is no space between rows unless you set a gap.
grid-row-gap sets only row spacing. gap is shorthand for both row-gap and column-gap together.
Yes. row-gap is the modern standard name. grid-row-gap is the legacy grid-specific alias and still works in browsers.
No. Gap applies only between rows, not between the grid and the container top or bottom edges.

Practice in the Live Editor

Open the HTML editor, change grid-row-gap values, and see how row spacing updates.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful