Back to Blog
CSSgapFlexboxGrid

CSS gap Property Guide

Master the CSS gap property for adding consistent spacing in flexbox and grid layouts.

B
Bootspring Team
Engineering
May 27, 2019
5 min read

The gap property adds space between grid and flexbox items without affecting outer edges. Here's how to use it effectively.

Basic Syntax#

Loading code block...

With Flexbox#

Loading code block...

With Grid#

Loading code block...

Card Layouts#

Loading code block...
Loading code block...

Button Groups#

Loading code block...

Form Layouts#

Loading code block...

Tag/Chip Lists#

Loading code block...
Loading code block...

Responsive Gap#

Loading code block...

Nested Layouts#

Loading code block...

vs Margin Approach#

Loading code block...
Loading code block...

Centered Content#

Loading code block...

Best Practices#

General Usage: ✓ Prefer gap over margins ✓ Use with flex and grid ✓ Combine row-gap and column-gap ✓ Use responsive values Sizing: ✓ Use rem for consistency ✓ Use clamp for fluid gaps ✓ Consider content density ✓ Match design system Patterns: ✓ Cards and grids ✓ Navigation items ✓ Form elements ✓ Button groups Avoid: ✗ Gap on non-flex/grid ✗ Negative gap values ✗ Mixing gap and margin ✗ Forgetting browser support

Conclusion#

The gap property simplifies spacing in flexbox and grid layouts by adding consistent space between items without affecting outer edges. It eliminates the need for negative margins and last-child selectors. Use single values for uniform spacing, two values for different row/column gaps, and combine with responsive breakpoints or clamp() for fluid layouts. Gap works with both flex and grid, making it the preferred way to handle spacing in modern CSS layouts.

Share this article

Help spread the word about Bootspring

Related articles