CSS gap Property

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

Definition and Usage

The gap property sets the gutters between rows and columns. It works on grid, flex, and multi-column containers.

It is a shorthand for row-gap and column-gap. One value sets both axes. Two values set row gap first, then column gap. The property is not inherited. The initial value is normal (0 in grid and flex; 1em in multi-column).

Standard-track.

Not deprecated and not experimental. Baseline Widely available. Early grid used the alias grid-gap; prefer gap in new CSS.

CSS Syntax

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

Each gap value is normal, a length such as 20px, a percentage, or calc().

Property Values

ValueDescriptionTry it
normalDefault. 0 in grid/flex; 1em in multi-columnTry it
<length>One size for both row and column gaps, such as 20pxTry it
<percentage>Percent of the container content box sizeTry it
Two valuesFirst = row-gap, second = column-gapTry it
initialResets to normalTry it
inheritTakes the parent’s gapTry it

Negative values are invalid. Gaps appear between tracks or items, never before the first or after the last.

How to Use gap

Create a flex, grid, or multi-column container, then set the gutter size on that container.

  1. Set display: grid, display: flex, or a multi-column layout on the container.
  2. Add gap with one value for equal gutters, or two values for row then column.
  3. Prefer gap over item margins when every item needs the same spacing.
  4. Use the longhands row-gap or column-gap when only one axis should change.
PieceRequired?Role
Flex, grid, or multi-column containerYesgap has no effect on a normal block box
Gap sizeYesLength, percentage, normal, or two values
Tracks or itemsYesYou need at least two tracks or items to see a gutter

Live Preview

A three-column grid. Only gap changes. Watch the space between the tiles grow or shrink.

Gutters sit between items only. Outer edges stay flush with the container padding.

Sample
1
2
3
4
5
6

gap: 16px

CSS Examples

Each snippet focuses on gap. Use Try It Yourself for a live editor.

Example 1 — Equal Grid Gap

One length spaces every row and column the same way.

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

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Make a grid. display: grid with three equal columns.
  2. Set one gap. gap: 20px applies 20px between rows and between columns.
  3. See the gutters. Space appears only between tiles, not outside the first or last track.
  4. Skip item margins. You do not need margin on each child for even spacing.

Example 2 — Different Row and Column Gaps

Two values: first is row gap, second is column gap.

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

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Read left to right. 10px is row-gap. 24px is column-gap.
  2. Compare the axes. Vertical space between rows is tighter than horizontal space between columns.
  3. Same as longhands. This matches row-gap: 10px; column-gap: 24px;.
  4. Use when designs differ. Cards often want more side space than stacked space.

Example 3 — Flexbox Gap

Space flex items without margin hacks.

CSS
<style>
  section {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
  }
</style>

<section>
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</section>
Try It Yourself

How It Works

  1. Make a flex row. display: flex lays children in a line.
  2. Allow wrapping. flex-wrap: wrap lets items form extra lines when needed.
  3. Add gutters. gap: 16px spaces items and lines without fighting margins.
  4. Two-value tip. On a row flex, gap: 8px 16px means 8px between lines and 16px between items.

Edge Cases & Pitfalls

If the spacing looks wrong, check these first.

block

Needs a flex, grid, or multi-column container

On a normal block box, gap does nothing. Set display: flex or display: grid first.

edges

No gap before the first or after the last

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

margin

Margins still add extra space

gap and margin stack. Large item margins can make the visual space larger than the gap value.

%

Percentages need a definite container size

Percent gaps resolve against the container content box. With an indefinite size, flex percent gaps can resolve to 0.

legacy

grid-gap is an old alias

Browsers still accept grid-gap. New code should use gap.

Browser Support

gap is a browser CSS property for layout gutters. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

gap

Grid support since about 2017. Flex gap since Chrome 84, Firefox 63, Safari 14.1, and Edge 84. Internet Explorer does not support it.

97% Global 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+ grid · flex in Chromium 84+
Full support
Samsung Internet 7.2+
Full support
Internet Explorer No
Not supported
gap Widely supported

Bottom line: Safe for grid and flex in current browsers. Prefer gap over grid-gap. Multi-column containers also accept gap for column gutters.

Key Takeaways

  • Role: set gutters between rows and columns in flex, grid, and multi-column layouts.
  • Shorthand: one value for both axes; two values = row-gap then column-gap.
  • Not inherited. Initial value is normal (0 in grid/flex).
  • Prefer over item margins for even spacing between siblings.

One line: gap is the clean way to space flex or grid items between each other without margin tricks.

Frequently Asked Questions

It sets the gutters between rows and columns on grid, flex, and multi-column containers. It is a shorthand for row-gap and column-gap.
The initial value is normal. In grid and flex that means 0. In multi-column layout, normal means 1em.
gap spaces items only between each other inside the container. margin adds space around one element and can push outside the layout. Prefer gap for even item spacing in flex and grid.
Yes in modern browsers. Flex gap is Baseline Widely available (Chrome 84+, Firefox 63+, Safari 14.1+, Edge 84+). Grid support landed earlier.
gap is the shorthand. One value sets both axes. Two values set row-gap first, then column-gap. The longhands control one axis each.
It is Baseline Widely available. Grid: Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+. Flex: Chrome 84+, Firefox 63+, Safari 14.1+, Edge 84+. Internet Explorer does not support it. It is a browser CSS property, not a Node.js feature.

Next: grid

Set grid tracks and auto-flow in one shorthand.

grid 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