CSS gap Property Explained
What the CSS gap property does, with an example.
Published November 4, 2026
gap sets the space between rows and columns in flex, grid and multi-column layouts: gap: <row> <column>. It replaces margin hacks.
How it works
Unlike margins, gap only adds space between items, not at the outer edges. It works in Flexbox in all modern browsers.
row-gap and column-gap set each axis separately.
Values and effects
gap: 1rem; → same in both directions
gap: 1rem 2rem; → row gap then column gap
gap: 0; → no gap
Practical examples
Grid gaps
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem 2rem; }Flex gap
.tags { display: flex; flex-wrap: wrap; gap: .5rem; }Column layout
.text { column-count: 2; column-gap: 2rem; }Common mistakes
- Using margins on items when gap is simpler.
- Expecting gap on block layouts (it needs flex/grid/columns).
- Forgetting row/column order in the shorthand.
Key takeaways
- gap in one line: gap sets the space between rows and columns in flex, grid and multi-column layouts: gap: <row> <column>.
- Inspect it live in DevTools → Styles.
- Test across browsers and screen sizes.
FAQ
gap vs margin?
gap spaces only between items and doesn't affect the edges.
Is gap supported in all browsers?
Yes in all modern browsers; check caniuse.com for edge cases.