CSS grid-gap Property
The grid-gap CSS property is used to define the size of the gap between the rows and columns. See this property in action.
The grid-gap property sets the size of the gap (gutter) between a grid layout's rows and columns. The gap is the empty space between grid tracks only — it never adds space on the outer edges of the grid, so the container's own padding still controls the outer margin.
grid-gap is a shorthand for two longhand properties:
- grid-row-gap — the gap size between rows.
- grid-column-gap — the gap size between columns.
grid-gap vs. gap
The standard gap property has replaced grid-gap. The two behave identically inside a grid container, but grid-gap is now considered legacy: it exists mainly for older browsers that shipped the grid-prefixed version before the unprefixed gap was standardized. Modern browsers still support grid-gap as an alias, so existing stylesheets keep working.
For new projects, prefer gap — it works in grid and flexbox layouts, whereas grid-gap only ever applied to grids:
/* Legacy (grid only) */
.grid { display: grid; grid-gap: 20px 40px; }
/* Modern, preferred */
.grid { display: grid; gap: 20px 40px; }| Initial Value | 0 |
|---|---|
| Applies to | Grid containers. |
| Inherited | No. |
| Animatable | Yes. grid-gap is animatable. |
| Version | CSS Grid Layout Module Level 1 |
| DOM Syntax | object.style.gridGap = "30px 70px"; |
Syntax
CSS grid-gap Property
grid-gap: <row-gap> <column-gap>;The property accepts one or two length values:
- One value sets the row gap and the column gap to the same size.
- Two values set the row gap first, then the column gap (
grid-gap: 20px 40px;means a 20px gap between rows and a 40px gap between columns).
Each value may be any non-negative length (px, em, rem, etc.) or a percentage. The keywords initial and inherit are also valid.
Example of the grid-gap property:
Example of a grid container with the grid-gap property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 60px;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-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>Result

Example of the grid-gap property specified in percentages:
A percentage gap is resolved against the grid container's own dimensions — the column gap is a percentage of the container's width, and the row gap is a percentage of its height. Percentages are handy for fluid layouts, but they make the gutter grow with the container, so fixed lengths are usually more predictable.
Example of a grid container where the grid gap is defined by percentages
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 20%;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-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>
</body>
</html>Example of the grid-gap property with two values:
When you pass two values, the first sets the row gap and the second sets the column gap. Here the rows are separated by 20px and the columns by 80px:
Example of a CSS grid-gap property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
grid-gap: 20px 80px;
background-color: #ccc;
padding: 10px;
}
.grid-container > div {
background-color: #666;
text-align: center;
padding: 20px 0;
font-size: 30px;
}
</style>
</head>
<body>
<h2>Grid-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>Values
| Value | Description | Play it |
|---|---|---|
| grid-row-gap | Specifies the size of the gap between the rows in a grid layout. The default value is 0. When using the two-value syntax, this corresponds to the first value. | |
| grid-column-gap | Specifies the size of the gap between the columns in a grid layout. The default value is 0. When using the two-value syntax, this corresponds to the second value. | Play it » |
| initial | Makes the property use its default value. | |
| inherit | Inherits the property from its parent element. |
Browser support
grid-gap is supported in all modern browsers. Because it is an alias for the standard gap property, you generally don't need both. If you must support very old grid implementations, you can list grid-gap for them and gap for everything else:
.grid {
display: grid;
grid-gap: 20px; /* fallback for legacy browsers */
gap: 20px; /* standard property wins where supported */
}Related properties
- grid-row-gap and grid-column-gap — the longhands
grid-gapcombines. - grid — the shorthand for an entire grid layout.
- grid-template-columns — defines the columns the gaps sit between.