Gap Spacing Property

Last updated: 2026-09-13

gap Gap Spacing Property

The gap property sets the spacing between rows and columns in flex and grid layouts. It is a shorthand for row-gap and column-gap. Gap only adds space between items and never at the container edges, which makes it cleaner and more predictable than margins. It removes the usual hassle of clearing the first and last margins in traditional margin-based spacing.

Category
Initial Valuenormal
InheritedNo
Applies To
Animation Type
CSS VersionCSS3
StatusStandard

📝 Syntax

gap: normal | <length> | <percentage>;

⚙️ Values

ValueTypeDescription
normalKeywordDefault spacing
<length> | <percentage>TypeRow and column spacing

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
gap v66 v16 v61 v10.1 v53
Supported in all major browsers
Tip: The two values of gap map to row-gap and column-gap: gap: 10px 20px means 10px between rows and 20px between columns. A single value applies to both.
Important: gap only works in flex and grid layouts; it has no effect in normal block layout. Use margin when you need spacing between block elements.

❓ FAQ

QWhat is the difference between gap and margin?
Agap only creates space between the items and never adds space at the container edges, so there are no first or last gaps to clean up. margin creates space on all sides of an element, so the first and last margins need special handling, and margins can interfere with the flex or grid sizing math. Prefer gap for internal layout spacing and keep margin for the space between an element and things outside it.
QHow is the browser support for gap?
AIn flex layouts gap is fully supported from Chrome 84, Firefox 63 and Safari 14.1 onward; in grid layouts it was supported much earlier (Chrome 66+, Safari 12+). Percentage values are also supported and resolve against the container size. To support older browsers, first implement the spacing with margin as a fallback, then use a @supports (gap: 1px) feature query to switch to the new syntax.
QWhat is the difference between gap and grid-gap, and why is gap recommended now?
Agrid-gap was the early syntax that only applied to grid, together with grid-row-gap and grid-column-gap. Later the spec extended gap to flex, grid and multi-column layouts and renamed the property. gap is now the shorthand for row-gap and column-gap, and those standalone properties remain valid and handy when only one direction needs a custom value. All modern browsers support gap; grid-gap is the legacy form, so new code should use gap.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏