CSS Portal

CSS gap Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The gap property controls the spacing between items in layout systems without placing that spacing on the items themselves. Instead of adding margins on children, it creates a dedicated gap area between adjacent grid tracks or flex items so the spacing is conceptually part of the container’s layout. That makes it easier to maintain consistent gutters: when you change the container’s spacing, you adjust a single value rather than updating margins on every child element.

In practice, gap only has an effect when the container participates in a layout model that understands inter-item gutters (for instance when a container is set to use a grid or flex layout), so it’s tied to how the container is displayed — see display. It is the shorthand relationship to the directional gap properties such as row-gap and column-gap, letting authors think in terms of a two-axis gutter instead of manually managing vertical and horizontal spacing separately.

Using gap changes how space is allocated inside the container: the gap area is considered when computing track sizes and available space, so adding a larger gap can reduce the space available for the items themselves. It does not collapse like margins, and it does not add extra empty space around the outer edges of the container — the gap exists only between items. Because of this separation, gap complements alignment properties; it does not replace alignment or distribution controls such as justify-content or align-items, which still determine how remaining space is positioned relative to item boxes. For cases where you previously relied on per-item margins to space children, replacing those margins with a container-level gap simplifies responsive tweaks and avoids uneven spacing caused by differing child wrappings or order.

Definition

Initial value
See individual properties
Applies to
multi-column elements, flex containers, grid containers
Inherited
no
Computed value
See individual properties
Animatable
See individual properties
JavaScript syntax
object.style.gap

Interactive Demo

Item One
Item Two
Item Three
Item Four
Item Five

Syntax

gap: <row-gap> <column-gap>

Values

  • <row-gap>Is the width of the gutter separating the grid lines.
  • <column-gap>Is the width of the gutter separating the grid lines.

Example

<div class="demo">
<h2>Flex gap</h2>
<div class="flex-container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>

<h2>Grid gap</h2>
<div class="grid-container">
<div class="card">A</div>
<div class="card">B</div>
<div class="card">C</div>
<div class="card">D</div>
<div class="card">E</div>
<div class="card">F</div>
</div>
</div>
.demo {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
    color: #333;
}

h2 {
    margin: 16px 0;
    font-size: 18px;
}

.flex-container {
    display: flex;
    gap: 1rem; /* horizontal gap between flex items */
    align-items: center;
    background: #f7f7f9;
    padding: 12px;
    border-radius: 8px;
}

.item {
    background: linear-gradient(180deg, #fff 0%, #f0f4ff 100%);
    border: 1px solid #e0e6f8;
    padding: 12px 18px;
    border-radius: 6px;
    box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}

.grid-container {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px 24px; /* row-gap column-gap */
    background: #fff;
    padding: 12px;
    border-radius: 8px;
}

.card {
    background: #fff7ef;
    border: 1px solid #ffe6cc;
    padding: 16px;
    text-align: center;
    border-radius: 6px;
}

Browser Support

The following information will show you the current browser support for the CSS gap property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!