flexbox

gap

Shorthand for row-gap and column-gap, setting spacing between flex, grid, or multi-column items. Replaces margin hacks for evenly spacing children.

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

Common values

Value Effect
0 No gap between items
1rem Even 1rem gap on both axes
8px 16px 8px row gap, 16px column gap
clamp(.5rem, 2vw, 1.5rem) Fluid responsive gap

Examples

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

Three-column grid with equal spacing

.stack { display: flex; flex-direction: column; gap: 1rem; }

Vertical stack with breathing room

.form { display: grid; gap: .5rem 1rem; }

Tighter vertical, wider horizontal spacing

Gotcha

gap does not add space outside the container edges; use padding on the parent for that.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox