CSS row-gap Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Grid & Flexbox

What You’ll Learn

The row-gap property sets vertical space between rows in grid and flex layouts. It is cleaner than adding bottom margins to every child.

01

normal

Default gap.

02

px

Fixed space.

03

rem

Scalable.

04

grid

Row spacing.

05

flex

Stacked items.

06

gap

Shorthand.

Introduction

The row-gap property in CSS is used to set the vertical spacing (gap) between rows in grid and flexbox layouts.

It is an essential property for controlling the layout and spacing of elements in a more manageable and visually appealing way.

Definition and Usage

Apply row-gap on the container, not on individual children. In CSS Grid, it adds space between horizontal grid tracks. In a flex column, it adds space between stacked items.

Pair row-gap with column-gap when you need different vertical and horizontal spacing, or use the gap shorthand when both axes should match.

💡
Beginner Tip

Gap properties create space between items only. They do not add outer padding around the whole container.

📝 Syntax

The syntax for the row-gap property is straightforward. It can be applied to grid and flexbox containers to specify the space between rows.

syntax.css
container {
  row-gap: value;
}

Here, value can be any valid CSS length unit, such as px, em, rem, %, vh, vw, etc.

Basic Example

row-gap-grid.css
.grid-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  row-gap: 20px;
}

Syntax Rules

  • Apply row-gap on the grid or flex container.
  • Use length units like px or rem for predictable spacing.
  • normal is the default and usually means no extra row gap.
  • Percentages are relative to the container size in grid layouts.
  • Combine with column-gap for separate horizontal spacing.
  • Use gap: row column shorthand when both values are needed.

🎯 Default Value

The default value of the row-gap property is normal, which means the browser will use its default spacing. For grid layouts, this usually means no additional space between rows.

⚡ Quick Reference

QuestionAnswer
Default valuenormal
Applies toGrid and flex containers
ControlsVertical space between rows
Shorthandgap (with column-gap)
InheritedNo
AnimatableYes (length values)

💎 Property Values

ValueExampleDescription
lengthrow-gap: 20px;Specifies a fixed gap between rows, such as 10px, 1em, etc.
percentagerow-gap: 10%;Specifies a gap relative to the size of the container, such as 10%.
normalrow-gap: normal;The browser’s default row gap, which is usually 0.
normal 20px 1.25rem 10%

When Does row-gap Matter?

row-gap is the right tool when vertical rhythm needs to be consistent:

  • Card grids — Separate rows of dashboard tiles without margin hacks.
  • Form sections — Stack fields evenly in a flex column.
  • Image galleries — Keep row breathing room in responsive grids.
  • Design systems — Use rem gaps that scale with typography.

If both row and column spacing are equal, gap: 20px is shorter than setting each longhand separately.

👀 Live Preview

This 2-column grid uses row-gap: 1rem between the two rows.

1
2
3
4

Only vertical space between rows is controlled by row-gap.

Examples Gallery

Start with the reference grid, compare zero vs spaced rows, use flex columns, and scale gaps with rem.

▦ Grid Row Spacing

Add vertical space between grid rows — matching the reference example.

Example 1 — Grid with row-gap

In this example, we’ll create a simple grid layout with a specified row gap.

row-gap-grid.html
<style>
  .grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    row-gap: 20px;
  }
</style>

<div class="grid-container">
  <div class="grid-item">Item 1</div>
  <div class="grid-item">Item 2</div>
  <div class="grid-item">Item 3</div>
  <div class="grid-item">Item 4</div>
</div>
Try It Yourself

How It Works

The gap appears only between row tracks. Items in the same row are unaffected by row-gap.

Example 2 — Zero vs Spaced Rows

Compare row-gap: 0 with row-gap: 24px to see how vertical rhythm changes.

row-gap-compare.html
<style>
  .tight { row-gap: 0; }
  .spaced { row-gap: 24px; }
</style>
Try It Yourself

How It Works

Changing only row-gap adjusts vertical spacing without touching column layout or item padding.

🔀 Flex & Responsive Gaps

Use row-gap beyond basic grids for stacked and scalable layouts.

Example 3 — Flex Column Stack

In a column flex layout, row-gap adds even spacing between stacked cards.

row-gap-flex.html
<style>
  .stack {
    display: flex;
    flex-direction: column;
    row-gap: 16px;
  }
</style>
Try It Yourself

How It Works

Flex gap avoids the last-child margin problem because spacing is managed by the container.

Example 4 — rem-Based Dashboard Grid

Use row-gap: 1.25rem so vertical spacing grows consistently with root font size.

row-gap-rem.html
<style>
  .dashboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    row-gap: 1.25rem;
  }
</style>
Try It Yourself

How It Works

rem gaps help dashboards stay visually balanced when users change default font size.

row-gap, column-gap, and gap

row-gap controls vertical spacing only. column-gap controls horizontal spacing. gap is the shorthand for both.

Example: gap: 24px 12px sets row-gap: 24px and column-gap: 12px.

gap-shorthand.css
.cards {
  display: grid;
  row-gap: 1.5rem;
  column-gap: 1rem;
}

🧠 How row-gap Works

1

Create a layout container

Use display: grid or display: flex on the parent.

Container
2

Set row-gap

Choose a length, percentage, or normal for vertical spacing.

row-gap
3

Browser inserts gutters

Space appears between row tracks without margins on children.

Gutters
=

Cleaner layouts

Even vertical rhythm in grids and stacked flex UIs with one property.

Browser Compatibility

The row-gap property is widely supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Grid · Flex · Modern support

Reliable row-gap support

Current Chrome, Firefox, Safari, Edge, and Opera support row-gap in grid and flex layouts.

97% Modern browser support
Google Chrome 57+ grid · 84+ flex
Full support
Mozilla Firefox 52+ grid · 63+ flex
Full support
Apple Safari 10.1+ grid · 14.1+ flex
Full support
Microsoft Edge 16+ grid · 84+ flex
Full support
Opera 44+ · Modern versions
Full support

Testing tip

Flexbox gap support is slightly newer than grid gap. Test stacked flex layouts in Safari if you support older iOS versions.

row-gap property 97% supported

Bottom line: row-gap is widely supported for grid and modern flex layouts.

Conclusion

The row-gap property is a powerful tool for web developers looking to control the vertical spacing between rows in grid and flexbox layouts.

By customizing the row gap, you can create more visually appealing and well-structured layouts. Experiment with different values to see how this property can enhance the look and feel of your web projects.

💡 Best Practices

✅ Do

  • Set row-gap on the container, not children
  • Use rem for scalable design-system spacing
  • Pair with column-gap when axes need different values
  • Prefer gap over margin stacks for equal vertical rhythm
  • Test flex column layouts in target browsers

❌ Don’t

  • Expect row-gap to work on non-layout containers
  • Combine gap and conflicting child margins without checking spacing
  • Use huge percentage gaps without testing narrow screens
  • Forget that gap does not replace outer container padding
  • Duplicate row-gap and gap on the same rule unnecessarily

Key Takeaways

Knowledge Unlocked

Five things to remember about row-gap

Use these points when spacing rows in grid and flex layouts.

5
Core concepts
02

Vertical

Row spacing.

Purpose
03

grid

Track gutters.

Use case
04

flex

Stacked items.

Context
05

gap

Shorthand.

Companion

❓ Frequently Asked Questions

row-gap sets the vertical space between rows in a grid container or between flex items when they stack into multiple rows or a column layout.
row-gap controls only vertical spacing. gap is a shorthand that can set both row-gap and column-gap in one declaration.
The default value is normal, which typically means no extra row spacing (0 in practice for grid and flex).
Yes. row-gap works in modern flex layouts, especially useful with flex-direction: column or wrapped flex rows.
row-gap controls vertical spacing between rows. column-gap controls horizontal spacing between columns.

Practice in the Live Editor

Open the HTML editor and build a grid with row-gap: 20px.

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