Skip to main contentSkip to docs navigation

Chassis

The gap between grid items, set per breakpoint by the gutter tokens and overridable per grid with a custom property or the gap utilities.

@layer layout
Viewport queries
Scoped tokens

Overview

The gutter is the gap between the items of a .grid or .grid-fill, between columns and between rows. It is a design token with a value per breakpoint, declared on :root as --cx-grid-gutter, so a grid needs no class to have the gutter of the current viewport.

BreakpointDimensionsGutter
xs<576px1rem
sm≥576px1rem
md≥768px1.5rem
lg≥1024px1.5rem
xl≥1280px1.5rem
2xl≥1536px1.5rem
.col-span-6
.col-span-6
.col-span-6
.col-span-6
HTML
<div class="grid text-center">
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
</div>

The gutter is a gap: it sits between items only, never at the edges of the grid, so a grid needs no negative margin and no wrapper to contain it.

Custom gap

--cx-grid-gap replaces the gutter for one grid, or for every grid inside the element that sets it. It takes any length.

.col-span-6
.col-span-6
.col-span-6
.col-span-6
HTML
<div class="grid text-center" style="--cx-grid-gap: .25rem;">
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
</div>

Two values set the row gap and the column gap, in that order:

Item
Item
Item
Item
HTML
<div class="grid grid-cols-2 text-center" style="--cx-grid-gap: .25rem 2rem;">
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
</div>

Gap utilities

The gap utilities set the gap from the spacing scale, the scale of the padding and margin utilities. A utility overrides both the gutter and --cx-grid-gap.

The sizes of the gap utilities are fixed steps of the spacing scale. .gap-md is the md space at every viewport width; it shares a name with the md breakpoint and nothing else.

Both axes

.gap-{size} sets the gap between columns and between rows.

.col-span-6
.col-span-6
.col-span-6
.col-span-6
HTML
<div class="grid gap-xs text-center">
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
</div>

Horizontal gaps

.column-gap-{size} sets the gap between columns and leaves the row gap at the gutter.

Item
Item
Item
Item
HTML
<div class="grid grid-cols-2 column-gap-3xl text-center">
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
</div>

Vertical gaps

.row-gap-{size} sets the gap between rows and leaves the column gap at the gutter.

.col-span-6
.col-span-6
.col-span-6
.col-span-6
HTML
<div class="grid row-gap-0 text-center">
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
  <div class="col-span-6">.col-span-6</div>
</div>

Responsive gaps

Every gap utility has breakpoint variants — .{breakpoint}:gap-{size}, .{breakpoint}:column-gap-{size}, .{breakpoint}:row-gap-{size} — and combines with the column counts. The grid below has two columns and a small gap, then five columns and a larger gap from the lg breakpoint:

Item
Item
Item
Item
Item
Item
Item
Item
Item
Item
HTML
<div class="grid grid-cols-2 lg:grid-cols-5 gap-xs lg:gap-md text-center">
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
  <div>Item</div>
</div>

No gap

.gap-0 removes the gap on both axes. Spans, start lines, and ordering are unaffected.

.sm:col-span-6 .md:col-span-8
.col-span-6 .md:col-span-4
HTML
<div class="grid gap-0 text-center">
  <div class="col-span-full sm:col-span-6 md:col-span-8">.sm:col-span-6 .md:col-span-8</div>
  <div class="col-span-6 md:col-span-4">.col-span-6 .md:col-span-4</div>
</div>

Narrow grids

The gutter follows the width of the viewport, not the width of the grid. A grid that fills the page gets a gap in proportion to it; a grid in a sidebar, a card, or a grid item gets the same gap in a fraction of the width. The tracks shrink to make room and the gaps do not: twelve tracks have eleven gaps between them, so a .grid narrower than eleven gutters overflows its parent. With the default tokens that is 11rem below the md breakpoint and 16.5rem from it.

A narrow grid takes fewer tracks, with a column count, or a gap of its own, with --cx-grid-gap or a gap utility. .contained on the grid, inside a query container, gives it the gutter of the width of that container, which is no narrower than the gutter of the first breakpoint — see Contained grids.

Sidebar
Item
Item
Item
Item
HTML
<div class="grid text-center">
  <div class="col-span-4">Sidebar</div>
  <div class="col-span-8">
    <div class="grid grid-cols-2 gap-xs">
      <div>Item</div>
      <div>Item</div>
      <div>Item</div>
      <div>Item</div>
    </div>
  </div>
</div>

Outside a grid

--cx-grid-gutter is declared on :root, so any element can read it. A flex row gets the gutter of the grid with one declaration:

CSS
.toolbar {
  display: flex;
  gap: var(--cx-grid-gutter);
}

Page margin

The padding of .container is the page margin, --cx-container-padding: a value of its own, with its own tokens, that does not follow the gutter. A grid in a container starts at the padding edge of the container at every breakpoint. See Containers.

CSS

Gutter systems can be customized at both runtime (via custom properties) and compile time (via Sass variables).

Custom properties

Two custom properties set the gap of a grid: the gutter of the breakpoint, and the override of one grid.

PropertyDefaultDescription
--cx-grid-gutter:root, from $grid-guttersGutter of the current breakpoint; .grid.contained sets it by the width of its query container
--cx-grid-gap--cx-grid-gutterGap of .grid and .grid-fill; one value, or row-gap column-gap

Sass maps

$grid-gutters holds the gutter of each breakpoint. Override the map, or the tokens it reads, before importing Chassis. A breakpoint whose gutter equals that of the breakpoint before it emits no declaration.

$grid-gutters: (
  xs:           $gutter-xsmall,
  sm:           $gutter-small,
  md:           $gutter-medium,
  lg:           $gutter-large,
  xl:           $gutter-xlarge,
  2xl:          $gutter-2xlarge
);

The gap utilities are generated from $spaces, the spacing scale.

$spaces: (
  zero:           $space-zero,
  4xs:            $space-4xsmall,
  3xs:            $space-3xsmall,
  2xs:            $space-2xsmall,
  xs:             $space-xsmall,
  sm:             $space-small,
  md:             $space-medium,
  lg:             $space-large,
  xl:             $space-xlarge,
  2xl:            $space-2xlarge,
  3xl:            $space-3xlarge,
  4xl:            $space-4xlarge,
  5xl:            $space-5xlarge,
  6xl:            $space-6xlarge,
);

Design tokens

Gutter systems consume design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.

$gutter-2xlarge:          $cx-grid-gutter-2xlarge;
$gutter-xlarge:           $cx-grid-gutter-xlarge;
$gutter-large:            $cx-grid-gutter-large;
$gutter-medium:           $cx-grid-gutter-medium;
$gutter-small:            $cx-grid-gutter-small;
$gutter-xsmall:           $cx-grid-gutter-xsmall;