Skip to main contentSkip to docs navigation

Chassis

Containers

View on GitHub

Responsive wrappers that pad and center content with a configurable max-width at each breakpoint.

@layer layout
Viewport queries
Scoped tokens

.container applies width: 100%, the page margin as padding-inline, and margin-inline: auto to create a centered, padded wrapper. Containers can be nested, though most layouts require only one.

Available containers

Container classes differ only in when max-width takes effect:

  • .container — applies a max-width at each breakpoint
  • .container.{breakpoint} — width: 100% until the named breakpoint, then applies max-width for that breakpoint and wider
  • .container.fluid — width: 100% at all breakpoints; no max-width cap
xs
<576px
sm
≥576px
md
≥768px
lg
≥1024px
xl
≥1280px
2xl
≥1536px
.container100%540px720px960px1200px1440px
.container.sm100%540px720px960px1200px1440px
.container.md100%100%720px960px1200px1440px
.container.lg100%100%100%960px1200px1440px
.container.xl100%100%100%100%1200px1440px
.container.2xl100%100%100%100%100%1440px
.container.fluid100%100%100%100%100%100%

Default container

.container is full-width below the sm breakpoint and gains a fixed max-width at each wider breakpoint.

HTML
<div class="container">
  ...
</div>

Responsive containers

Each responsive variant is width: 100% below its named breakpoint, then applies max-width for that breakpoint and wider. For example, .container.sm is full-width below the sm breakpoint and scales up through md, lg, xl, and 2xl. See Breakpoints for the width of each breakpoint.

HTML
<div class="container sm">...</div>
<div class="container md">...</div>
<div class="container lg">...</div>
<div class="container xl">...</div>
<div class="container 2xl">...</div>

Fluid containers

.container.fluid is width: 100% at every breakpoint with no max-width cap.

HTML
<div class="container fluid">
  ...
</div>

Padding

The inline padding of a container is the page margin: --cx-container-padding, declared on :root per breakpoint from the margin tokens. It is a value of its own and does not follow the gutter of the grid, so the margin of the page and the gap between columns can differ, as they do in a Figma layout grid.

xssmmdlgxl2xl
Page margin1rem1rem1.5rem1.5rem1.5rem1.5rem

.px-0 removes the padding of one container, for content that runs to the edges of the viewport. Other padding utilities replace it.

HTML
<div class="container fluid px-0">
  ...
</div>

--cx-container-padding set on an element changes the padding of the containers inside it:

HTML
<main style="--cx-container-padding: 2rem;">
  <div class="container">...</div>
</main>

Before v0.6.0 the padding was half of --cx-gutter-x, the gutter of the flexbox grid. v0.6.0 padded with --cx-container-padding and still read a --cx-gutter-x set on the container. As of v0.7.0 that property no longer changes the padding: set --cx-container-padding to the padding itself, half of the old value.

CSS

The Container system can be customized at both runtime (via custom properties) and compile time (via Sass variables).

$container-max-widths generates the container classes, and $enable-container-classes: false leaves them out of the build.

Sass maps

Override $container-max-widths before importing Chassis CSS to change the max-width at each breakpoint.

$container-max-widths: (
  sm:           $container-small,
  md:           $container-medium,
  lg:           $container-large,
  xl:           $container-xlarge,
  2xl:          $container-2xlarge
);

$container-paddings holds the padding of each breakpoint. Set every key to 0 for containers with no padding.

$container-paddings: (
  xs:           $margin-xsmall,
  sm:           $margin-small,
  md:           $margin-medium,
  lg:           $margin-large,
  xl:           $margin-xlarge,
  2xl:          $margin-2xlarge
);

$container-padding-x was removed in v0.7.0. Set $container-paddings instead, with half of the old value at every breakpoint. make-container() lost its $gutter parameter in the same release: set --cx-container-padding on the selector for a padding of its own.

Design tokens

The Container system consumes design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.

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

Sass mixins

make-container() applies the same base styles as .container — width: 100%, the padding of --cx-container-padding, and centered margins — without the breakpoint max-width overrides.

/// Generate a full-width, horizontally-centered container. Its padding is
/// `--container-padding`, the page margin `grid-root-vars()` sets per
/// breakpoint.
@mixin make-container() {
  width: 100%;
  padding-inline: var(--container-padding);
  margin-inline-start: auto;
  margin-inline-end: auto;
}

Apply it in a custom selector to build a container without using the .container class:

SCSS
.custom-container {
  @include make-container();
}