Responsive utilities for controlling gap, row-gap, and column-gap on flex and grid containers using the Chassis spacing scale.
Overview
Gap utilities apply the CSS gap, row-gap, and column-gap properties to flex and grid containers, distributing space between items without adding margin to individual children. All three utilities are responsive and share the same $spaces spacing scale used by margin and padding.
Notation
Gap classes that apply at all breakpoints have no breakpoint prefix — they start from min-width: 0 and are not media-query-bound. Breakpoint-prefixed classes apply at that breakpoint and above.
The classes are named using the format {property}-{size} for xsmall and {breakpoint}:{property}-{size} for small, medium, large, xlarge, and 2xlarge.
Where property is one of:
gap— setsgap(both row and column gap simultaneously)row-gap— setsrow-gapcolumn-gap— setscolumn-gap
Where size is one of:
zeroor0— eliminates the gap by setting it to04xsmall— default token value is0.0625rem(1px).3xsmall— default token value is0.125rem(2px).2xsmall— default token value is0.25rem(4px).xsmall— default token value is0.5rem(8px).medium— default token value is1rem(16px).large— default token value is1.25rem(20px).xlarge— default token value is1.5rem(24px).2xlarge— default token value is1.75rem(28px).3xlarge— default token value is2rem(32px).4xlarge— default token value is2.25rem(36px).5xlarge— default token value is2.5rem(40px).6xlarge— default token value is3rem(48px).
There is no .gap-auto class — auto has no defined behavior for gap in the CSS specification.
gap
.gap-{size} sets gap on a flex or grid container, controlling spacing between all items in both directions at once.
<div class="grid gap-medium">
<div class="g-col-6 p-xsmall">Item 1</div>
<div class="g-col-6 p-xsmall">Item 2</div>
<div class="g-col-6 p-xsmall">Item 3</div>
<div class="g-col-6 p-xsmall">Item 4</div>
</div>row-gap
.row-gap-{size} controls vertical spacing between rows in a grid or flex container without affecting column spacing.
<div class="grid gap-0 row-gap-medium">
<div class="g-col-6 p-xsmall">Item 1</div>
<div class="g-col-6 p-xsmall">Item 2</div>
<div class="g-col-6 p-xsmall">Item 3</div>
<div class="g-col-6 p-xsmall">Item 4</div>
</div>column-gap
.column-gap-{size} controls horizontal spacing between columns in a grid or flex container without affecting row spacing.
<div class="grid gap-0 column-gap-medium">
<div class="g-col-6 p-xsmall">Item 1</div>
<div class="g-col-6 p-xsmall">Item 2</div>
<div class="g-col-6 p-xsmall">Item 3</div>
<div class="g-col-6 p-xsmall">Item 4</div>
</div>CSS
Gap utilities are generated via the utilities API in scss/utilities/_gap.scss.
Reference
Each class name, its CSS property, and the generated values appear in the reference table.
| Class | Properties |
|---|---|
.gap-zero | gap: var(--cx-space-zero); |
.gap-4xsmall | gap: var(--cx-space-4xsmall); |
.gap-3xsmall | gap: var(--cx-space-3xsmall); |
.gap-2xsmall | gap: var(--cx-space-2xsmall); |
.gap-xsmall | gap: var(--cx-space-xsmall); |
.gap-small | gap: var(--cx-space-small); |
.gap-medium | gap: var(--cx-space-medium); |
.gap-large | gap: var(--cx-space-large); |
.gap-xlarge | gap: var(--cx-space-xlarge); |
.gap-2xlarge | gap: var(--cx-space-2xlarge); |
.gap-3xlarge | gap: var(--cx-space-3xlarge); |
.gap-4xlarge | gap: var(--cx-space-4xlarge); |
.gap-5xlarge | gap: var(--cx-space-5xlarge); |
.gap-6xlarge | gap: var(--cx-space-6xlarge); |
.gap-0 | gap: 0; |
.row-gap-zero | row-gap: var(--cx-space-zero); |
.row-gap-4xsmall | row-gap: var(--cx-space-4xsmall); |
.row-gap-3xsmall | row-gap: var(--cx-space-3xsmall); |
.row-gap-2xsmall | row-gap: var(--cx-space-2xsmall); |
.row-gap-xsmall | row-gap: var(--cx-space-xsmall); |
.row-gap-small | row-gap: var(--cx-space-small); |
.row-gap-medium | row-gap: var(--cx-space-medium); |
.row-gap-large | row-gap: var(--cx-space-large); |
.row-gap-xlarge | row-gap: var(--cx-space-xlarge); |
.row-gap-2xlarge | row-gap: var(--cx-space-2xlarge); |
.row-gap-3xlarge | row-gap: var(--cx-space-3xlarge); |
.row-gap-4xlarge | row-gap: var(--cx-space-4xlarge); |
.row-gap-5xlarge | row-gap: var(--cx-space-5xlarge); |
.row-gap-6xlarge | row-gap: var(--cx-space-6xlarge); |
.row-gap-0 | row-gap: 0; |
.column-gap-zero | column-gap: var(--cx-space-zero); |
.column-gap-4xsmall | column-gap: var(--cx-space-4xsmall); |
.column-gap-3xsmall | column-gap: var(--cx-space-3xsmall); |
.column-gap-2xsmall | column-gap: var(--cx-space-2xsmall); |
.column-gap-xsmall | column-gap: var(--cx-space-xsmall); |
.column-gap-small | column-gap: var(--cx-space-small); |
.column-gap-medium | column-gap: var(--cx-space-medium); |
.column-gap-large | column-gap: var(--cx-space-large); |
.column-gap-xlarge | column-gap: var(--cx-space-xlarge); |
.column-gap-2xlarge | column-gap: var(--cx-space-2xlarge); |
.column-gap-3xlarge | column-gap: var(--cx-space-3xlarge); |
.column-gap-4xlarge | column-gap: var(--cx-space-4xlarge); |
.column-gap-5xlarge | column-gap: var(--cx-space-5xlarge); |
.column-gap-6xlarge | column-gap: var(--cx-space-6xlarge); |
.column-gap-0 | column-gap: 0; |
Sass maps
Gap utilities are generated from Sass maps in scss/maps/_spacing.scss.
$spaces: (
zero: $space-zero,
4xsmall: $space-4xsmall,
3xsmall: $space-3xsmall,
2xsmall: $space-2xsmall,
xsmall: $space-xsmall,
small: $space-small,
medium: $space-medium,
large: $space-large,
xlarge: $space-xlarge,
2xlarge: $space-2xlarge,
3xlarge: $space-3xlarge,
4xlarge: $space-4xlarge,
5xlarge: $space-5xlarge,
6xlarge: $space-6xlarge,
);$-gap-values is derived from $spaces in scss/utilities/_gap.scss, resolving each spacing key to its :root custom property via var(--space-*), plus 0.
// Build a gap values map from $spaces. Each key maps to its :root spacing variable, plus 0.
$-gap-values: map.merge(map-loop($spaces, varify, "$key", "space"), (0: 0));Utilities API
Gap utilities are declared in scss/utilities/_gap.scss using the utilities API.
"gap": (
responsive: true,
property: gap,
class: gap,
values: $-gap-values
),
"row-gap": (
responsive: true,
property: row-gap,
class: row-gap,
values: $-gap-values
),
"column-gap": (
responsive: true,
property: column-gap,
class: column-gap,
values: $-gap-values
),