CSS grid-gap Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The grid-gap property is a shorthand that sets gutters between rows and columns in a CSS grid. Space appears only between tracks — not on the outer edges of the grid.

For new CSS, prefer gap. It is the modern name for the same shorthand and also works on flex and multi-column. Set it on a display: grid container with grid-template-columns.

Deprecated name · Legacy alias.

grid-gap is a legacy alias of gap. It still works in browsers; write gap in new code. Baseline Widely available.

CSS Syntax

syntax.css
grid-gap: <row-gap> <column-gap>? | initial | inherit;

One value sets both axes. Two values set row-gap first, then column-gap. Negative lengths are invalid. On grid, normal means no gutter (0).

Property Values

ValueDescriptionTry it
One lengthSame gutter for rows and columns (e.g. 16px)Try it
Two lengthsRow gap then column gap (e.g. 10px 24px)Try it
rem / %Root-relative or percent of the grid content boxTry it
normal / 0Default on grid — no guttersTry it
initialResets to normal on both axesTry it
inheritUses the parent’s gap valuesTry it

How to Use grid-gap

Build a grid, then set gutters with one shorthand. Prefer gap for new stylesheets.

  1. Create a grid with display: grid and column (and optional row) tracks.
  2. Set grid-gap (or better, gap) to one or two lengths.
  3. Use two or more rows and columns so both gutters are visible.
  4. Or set axes separately with grid-row-gap / grid-column-gap (prefer row-gap / column-gap).
PieceRequired?Role
display: gridYesMakes a grid formatting context
Multiple tracksYes (to see gaps)At least two rows or columns
Gap sizeYesOne or two lengths / percentages
Modern aliasRecommendedWrite gap in new CSS

Live Preview

A 3×2 grid. Change only grid-gap on the container.

One value sets both axes. Two values are row then column. Outer edges stay flush.

Grid

grid-gap: 16px

CSS Examples

Each snippet focuses on grid-gap. Prefer gap in production. Use Try It Yourself for a live editor.

Example 1 — One Value

Use the same gutter for rows and columns.

CSS
<style>
  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 16px;
  }
</style>

<div class="grid">
  <div>1</div><div>2</div><div>3</div>
  <div>4</div><div>5</div><div>6</div>
</div>
Try It Yourself

How It Works

  1. Make a grid. display: grid enables grid layout.
  2. Define columns. Three 1fr tracks share the width; items wrap into rows.
  3. One gap value. grid-gap: 16px sets both row and column gutters to 16px.
  4. Modern twin. gap: 16px does the same with the current name.

Example 2 — Two Values

Set a tighter row gap and a wider column gap.

CSS
<style>
  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 10px 24px;
  }
</style>

<div class="grid">
  <div>1</div><div>2</div><div>3</div>
  <div>4</div><div>5</div><div>6</div>
</div>
Try It Yourself

How It Works

  1. Order matters. First value = row gap; second = column gap.
  2. Read 10px 24px. 10px between rows, 24px between columns.
  3. Same as longhands. Equivalent to row-gap: 10px and column-gap: 24px.
  4. Prefer gap. gap: 10px 24px is the modern spelling.

Example 3 — rem Gap

Scale both gutters with the root font size.

CSS
<style>
  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-gap: 1rem;
  }
</style>

<div class="grid">
  <div>A</div><div>B</div><div>C</div>
  <div>D</div><div>E</div><div>F</div>
</div>
Try It Yourself

How It Works

  1. Same grid pattern. Three columns so both axes show spacing.
  2. Use rem. 1rem ties gutters to the root font size (often 16px).
  3. Why rem helps. User or theme font scaling also scales the gaps.
  4. Still an alias. Writing gap: 1rem is preferred in new CSS.

Edge Cases & Pitfalls

If spacing looks wrong, check these first.

legacy

Prefer gap in new CSS

grid-gap still works as an alias. Teach and write gap going forward — it also covers flex and multi-column.

edges

No gap on the outer edges

Gutters sit only between tracks. Use padding or margin on the container for outer inset.

order

Two values are row, then column

grid-gap: 10px 24px is not “x then y” in canvas terms — it is vertical gutter first, then horizontal.

align

Extra space can look larger than the gap

align-content / justify-content can add space between tracks on top of the gap value.

negative

Negative values are invalid

A negative length is ignored. Use 0 or a positive length/percentage only.

Browser Support

grid-gap is a browser CSS property (legacy alias of gap). Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

grid-gap

Supported everywhere modern Grid works as an alias of gap. Prefer gap in new stylesheets.

97% Modern browser support
Google Chrome 57+
Full support
Mozilla Firefox 52+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 16+
Full support
Opera 44+
Full support
Samsung Internet 6+
Full support
Internet Explorer No (use prefixes / polyfills)
Not supported
grid-gap Widely supported (alias)

Bottom line: Safe on modern browsers. Use gap for new code; keep grid-gap only when maintaining older Grid CSS. It is not a runtime API.

Key Takeaways

  • Role: shorthand for row and column gutters in a grid.
  • Legacy alias: same as gap — prefer that name now.
  • Two values: row gap first, column gap second.
  • Default on grid: normal → no gutters.

One line: grid + grid-gap: 16px; (or gap) = space between rows and columns.

Frequently Asked Questions

It is a shorthand that sets the gutters between rows and columns in a CSS grid. One value sets both axes; two values set row-gap then column-gap.
Yes as a preferred name. Use gap in new CSS. grid-gap remains a supported legacy alias so older Grid code keeps working.
Both row-gap and column-gap default to normal, which computes to 0 on grid (no gutters). Gaps never apply to the outer edges of the grid.
The first value is the row gutter (10px). The second is the column gutter (24px).
They do the same job. gap is the modern standard name and also works on flex and multi-column. Prefer gap for new stylesheets.
It is Baseline Widely available as an alias of gap. Chrome 57+, Edge 16+, Firefox 52+, Safari 10.1+, and modern Opera support it. Prefer gap for new work. It is a browser CSS property, not a Node.js feature.

Next: grid-row

Place a grid item with the row start and end shorthand.

grid-row tutorial →

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.

8 people found this page helpful