CSS grid-row-gap Property
Learn how CSS grid-row-gap sets gutter space between grid rows, with syntax, values, live examples, and tips for using the modern row-gap alias.
The grid-row-gap CSS property sets the size of the gap (the gutter) between the rows of a grid container. It inserts space between rows — never before the first row or after the last one — so it won't create unexpected outer margins.
This property only affects elements whose display is grid or inline-grid. It has no effect on flexbox or multi-column layouts; for those, use the standard column-gap property or the universal gap shorthand instead.
grid-row-gap is now an alias for the standard row-gap property, which works across grid, flexbox, and multi-column layouts. Browsers treat them identically inside a grid context. Prefer row-gap (or the grid-gap shorthand that sets both axes at once) in new code. grid-row-gap remains valid and is kept for backward compatibility.
Quick reference
| Initial value | normal (treated as 0 in grid) |
| Applies to | Grid containers |
| Inherited | No |
| Animatable | Yes |
| Spec | CSS Grid Layout Module Level 1 |
| DOM syntax | element.style.gridRowGap = "30px" |
When to use it
Reach for grid-row-gap when you want predictable vertical spacing between grid rows without relying on margins on individual grid items. Margins between grid items are awkward — they collapse unevenly, add space at the edges, and are harder to update globally. A row gap, by contrast, sits only between rows and keeps the grid's outer edges flush, which makes spacing easy to reason about.
Combine it with grid-column-gap for horizontal spacing, or replace both with the grid-gap shorthand when you want to set row and column gutters at the same time.
Syntax
/* keyword */
grid-row-gap: normal;
/* absolute length */
grid-row-gap: 20px;
grid-row-gap: 1.5em;
/* percentage of the container's block size */
grid-row-gap: 10%;
/* global values */
grid-row-gap: inherit;
grid-row-gap: initial;
grid-row-gap: unset;Values
| Value | Description |
|---|---|
normal | The browser's default spacing. Resolves to 0 inside a grid container. |
<length> | A non-negative CSS length value (px, em, rem, vw, etc.). |
<percentage> | A non-negative percentage resolved against the grid container's block-axis (height). |
inherit | Takes the computed value from the parent element. |
initial | Resets the property to its initial value (normal). |
unset | Acts as inherit if the property is inheritable, otherwise as initial. |
Examples
No row gap (default)
With grid-row-gap: 0, rows sit directly next to each other with no vertical gutter. Only the grid-column-gap separates items horizontally.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-column-gap: 20px;
grid-row-gap: 0;
background-color: #666;
padding: 10px;
}
.grid-container > div {
background-color: #eee;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-row-gap property example</h2>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div class="box8">8</div>
</div>
</body>
</html>
Fixed pixel gap
Setting grid-row-gap: 40px adds a 40-pixel gutter between every pair of rows. The column gap remains separate and is controlled independently by grid-column-gap.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-column-gap: 20px;
grid-row-gap: 40px;
background-color: #666;
padding: 10px;
}
.grid-container > div {
background-color: #eee;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-row-gap property example</h2>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</div>
</body>
</html>Percentage gap
A percentage value is resolved against the grid container's block size (its height). This means the gap grows proportionally when the container is taller, which can be useful for fluid, aspect-ratio-sensitive layouts. For most content layouts a fixed px or rem value is more predictable.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-row-gap: 15%;
grid-column-gap: 3%;
background-color: grey;
padding: 40px;
}
.grid-container > div {
background-color: white;
text-align: center;
padding: 25px;
font-size: 20px;
}
</style>
</head>
<body>
<div class="grid-container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</div>
</body>
</html>Migrating to the modern row-gap
The CSS Grid specification later aligned with the multi-column and flexbox gap conventions, renaming grid-row-gap to row-gap. The two are interchangeable inside a grid context, but row-gap also works in flexbox and multi-column containers. The migration is a one-line rename:
/* Legacy — still valid, but prefer row-gap in new code */
grid-row-gap: 20px;
/* Modern equivalent */
row-gap: 20px;
/* Shorthand: sets row-gap and column-gap at once */
gap: 20px 10px; /* row-gap: 20px; column-gap: 10px */
gap: 20px; /* both row-gap and column-gap: 20px */All major browsers have supported row-gap for grid since early 2020, so there is no practical compatibility reason to keep using the grid-row-gap name in new projects.
Common gotchas
- Percentage gaps and intrinsic height. When the grid container has no explicit
height, the browser cannot resolve a percentage row gap until it knows the container's height — which in turn depends on the content. This circular dependency can cause the gap to resolve to0. Usepxorremunless the container has a fixed height. - Negative values are not allowed. Unlike margins,
grid-row-gaponly accepts zero or positive values. Attempting to set a negative gap is invalid and the declaration is ignored. - The gap does not add outer space.
grid-row-gapadds space only between rows. If you need padding around the entire grid, use the container'spaddingproperty. - Spanning items are not affected. An item that spans multiple rows with
grid-row: span 2still benefits from the gap between those rows as part of its allocated space.
Related properties
grid-column-gap— sets the gap between grid columns.grid-gap— shorthand that sets bothgrid-row-gapandgrid-column-gapat once.column-gap— the modern, layout-agnostic property for column spacing.grid-template-columns— defines the column tracks the gap sits between.grid-template-rows— defines the row tracks separated by this gap.grid-auto-rows— controls the size of implicitly created rows.