Gap
Use gap utilities to control the space between elements in flexbox or grid layouts. Includes support for individual row and column gaps.
| Class | Styles |
|---|---|
| .gap-0 | gap: 0; |
| .gap-1 | gap: 0.25rem; |
| .gap-2 | gap: 0.5rem; |
| .gap-3 | gap: 1rem; |
| .gap-4 | gap: 1.5rem; |
| .gap-5 | gap: 3rem; |
| .row-gap-0 | row-gap: 0; |
| .row-gap-1 | row-gap: 0.25rem; |
| .row-gap-2 | row-gap: 0.5rem; |
| .row-gap-3 | row-gap: 1rem; |
| .row-gap-4 | row-gap: 1.5rem; |
| .row-gap-5 | row-gap: 3rem; |
| .column-gap-0 | -moz-column-gap: 0; column-gap: 0; |
| .column-gap-1 | -moz-column-gap: 0.25rem; column-gap: 0.25rem; |
| .column-gap-2 | -moz-column-gap: 0.5rem; column-gap: 0.5rem; |
| .column-gap-3 | -moz-column-gap: 1rem; column-gap: 1rem; |
| .column-gap-4 | -moz-column-gap: 1.5rem; column-gap: 1.5rem; |
| .column-gap-5 | -moz-column-gap: 3rem; column-gap: 3rem; |
Overview
Use gap utilities to control the space between children in flexbox and grid layouts. Gap utilities are built from a default Sass map ranging from .25rem to 3rem. Use utilities like .gap-3 and .gap-5 to control the gap between all children:
<div class="d-flex gap-3">...</div>
<div class="d-flex gap-5">...</div>Support note: Gap utilities work with CSS Grid and Flexbox layouts. They are a modern alternative to margin utilities for spacing children within a container.
Notation
Gap utilities that apply to all breakpoints, from xs to 2xl, have no breakpoint abbreviation in them. This is because those classes are applied from min-width: 0 and up, and thus are not bound by a media query. The remaining breakpoints, however, do include a breakpoint abbreviation.
The classes are named using the format {property}-{size} for xs and {property}-{breakpoint}-{size} for sm, md, lg, xl, and 2xl.
Where property is one of:
gap- for classes that setgaprow-gap- for classes that setrow-gapcolumn-gap- for classes that setcolumn-gap
Where size is one of:
0- for classes that eliminate thegapby setting it to01- (by default) for classes that set thegapto$spacer * .252- (by default) for classes that set thegapto$spacer * .53- (by default) for classes that set thegapto$spacer4- (by default) for classes that set thegapto$spacer * 1.55- (by default) for classes that set thegapto$spacer * 3
(You can add more sizes by adding entries to the $spacers Sass map variable.)
Examples
Flexbox gap
Use gap utilities to control the space between children in a flexbox container:
<div class="d-flex gap-4">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>Grid gap
Gap utilities also work with CSS Grid layouts:
<div class="d-grid gap-3" style="grid-template-columns: 1fr 1fr;">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</div>Row and column gaps
Use row-gap and column-gap utilities to control the space between rows and columns independently:
<div class="d-grid row-gap-4 column-gap-2" style="grid-template-columns: 1fr 1fr 1fr;">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>
<div>Item 6</div>
</div>Flexbox with wrapping
You can also use row-gap and column-gap utilities with flexbox layouts that wrap:
<div class="d-flex flex-wrap row-gap-3 column-gap-2">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
<div>Item 5</div>
</div>Responsive
All gap utilities are responsive and include all breakpoints.
.gap-0through.gap-5.gap-sm-0through.gap-sm-5.gap-md-0through.gap-md-5.gap-lg-0through.gap-lg-5.gap-xl-0through.gap-xl-5.gap-2xl-0through.gap-2xl-5
.row-gap-0through.row-gap-5.row-gap-sm-0through.row-gap-sm-5.row-gap-md-0through.row-gap-md-5.row-gap-lg-0through.row-gap-lg-5.row-gap-xl-0through.row-gap-xl-5.row-gap-2xl-0through.row-gap-2xl-5
.column-gap-0through.column-gap-5.column-gap-sm-0through.column-gap-sm-5.column-gap-md-0through.column-gap-md-5.column-gap-lg-0through.column-gap-lg-5.column-gap-xl-0through.column-gap-xl-5.column-gap-2xl-0through.column-gap-2xl-5
CSS
Sass utilities API
Gap utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.
"gap": (
responsive: true,
property: gap,
class: gap,
values: $spacers
),
"row-gap": (
responsive: true,
property: row-gap,
class: row-gap,
values: $spacers
),
"column-gap": (
responsive: true,
property: column-gap,
class: column-gap,
values: $spacers
),