Design Foundations

Containers

Use container size tokens for reusable width caps, component dimensions, and container query variants.

Overview

Containers define the size scale for reusable layout surfaces. In Master CSS, the container namespace has two related jobs:

  • Provide contextual size values such as max-w:md, w:3xl, size:lg, and flex-basis:sm.
  • Provide thresholds for @container(<name>) queries, so components can respond to the space they actually receive.

Use breakpoints for viewport-level page changes. Use containers for component-level adaptation and shared width caps.

TokenValuePXDescription
--container-3xs16rem256pxSmall component, compact card, or narrow popover.
--container-2xs18rem288pxCompact panel and constrained media region.
--container-xs20rem320pxSmall content module or sidebar-friendly component.
--container-sm24rem384pxComfortable card, form block, or narrow reading panel.
--container-md28rem448pxCommon component layout threshold.
--container-lg32rem512pxWide component or compact page section.
--container-xl36rem576pxLarge section, modal, or media composition.
--container-2xl42rem672pxSmall page wrapper or large split-pane region.
--container-3xl48rem768pxCompact page canvas.
--container-4xl56rem896pxStandard page canvas.
--container-5xl64rem1024pxReading or documentation wrapper.
--container-6xl72rem1152pxWide content wrapper.
--container-7xl80rem1280pxMaximum product canvas.
--container-8xl90rem1440px

Define container variables

Container tokens belong in the theme layer and use the container-* namespace.

@theme {    --container-sm: 24rem;    --container-md: 28rem;    --container-7xl: 80rem;}

The same token can drive a width cap and a container query. That keeps component dimensions and responsive thresholds from drifting apart. Container scale tables read from manifest metadata, so the displayed size and generated query stay aligned when tokens use rem, px, or legacy unitless numbers.


Namespace for container values

The container variable namespace is shared by width, height, min and max constraints, flex basis, intrinsic size, and media sizing utilities.

GroupUtility keysDescription
Preferred sizew, h, width, height, inline-size, block-size, size, size-x, size-ySet one axis or both axes from the shared container scale.
Minimum constraintsmin, min-w, min-h, min-size, min-size-x, min-size-y, min-width, min-height, min-inline-size, min-block-sizeKeep regions from collapsing below a reusable layout threshold.
Maximum constraintsmax, max-w, max-h, max-size, max-size-x, max-size-y, max-width, max-height, max-inline-size, max-block-sizeCap wrappers, panels, media, and content regions.
Layout basisflex-basisGive flex items a shared starting size before free space is distributed.
Intrinsic and media sizesbackground-size, mask-size, contain-intrinsic-inline-size, contain-intrinsic-block-sizeUse container tokens for reusable media and intrinsic size decisions.

This lets sizing utilities use md, 5xl, or project token names without the container- prefix. Container query variants use the same namespace for thresholds.


Use container values in sizing utilities

Sizing utilities that read from the container namespace use contextual shorthand. Write max-w:md; do not repeat the namespace inside the value.

<main class="w:full max-w:5xl mx:auto">    ...</main><aside class="flex-basis:md flex-shrink:0">...</aside>
Generated CSS
@layer theme {    :root {        --container-5xl: 64rem;        --container-md: 28rem    }}@layer utilities {    .mx\:auto {        margin-inline: auto    }    .flex-basis\:md {        flex-basis: var(--container-md)    }    .max-w\:5xl {        max-width: var(--container-5xl)    }    .w\:full {        width: 100%    }}

The shorthand is contextual: md can mean a container value inside max-w:md, and a breakpoint threshold inside @md. The utility or variant decides which namespace is active.

ValueTokenSizeExample utility
3xscontainer-3xs256px / 16remmax-w:3xs
2xscontainer-2xs288px / 18remmax-w:2xs
xscontainer-xs320px / 20remmax-w:xs
smcontainer-sm384px / 24remmax-w:sm
mdcontainer-md448px / 28remmax-w:md
lgcontainer-lg512px / 32remmax-w:lg
xlcontainer-xl576px / 36remmax-w:xl
2xlcontainer-2xl672px / 42remmax-w:2xl
3xlcontainer-3xl768px / 48remmax-w:3xl
4xlcontainer-4xl896px / 56remmax-w:4xl
5xlcontainer-5xl1024px / 64remmax-w:5xl
6xlcontainer-6xl1152px / 72remmax-w:6xl
7xlcontainer-7xl1280px / 80remmax-w:7xl
8xlcontainer-8xl1440px / 90remmax-w:8xl

Create a query container

Add container to the element whose inline size should be observed. Then apply @container(<size>) variants to descendants.

<section class="container">    <article class="grid-cols:1 grid-cols:2@container(md) gap:lg">        ...    </article></section>
Generated CSS
@layer theme {    :root {        --spacing-lg: 1.5rem    }}@layer utilities {    .container {        container-type: inline-size    }    .gap\:lg {        gap: var(--spacing-lg)    }    .grid-cols\:1 {        display: grid;        grid-template-columns: repeat(1, minmax(0, 1fr))    }    @container (width>=28rem) {        .grid-cols\:2\@container\(md\) {            display: grid;            grid-template-columns: repeat(2, minmax(0, 1fr))        }    }}

Container queries make components portable. The same card can be stacked in a sidebar and split into columns in a wide content region without knowing the viewport width.


Container query scale

Container query variants use the same container-* tokens as sizing utilities.

VariantValueGenerated query
@container(3xs)256px / 16rem@container (width>=16rem)
@container(2xs)288px / 18rem@container (width>=18rem)
@container(xs)320px / 20rem@container (width>=20rem)
@container(sm)384px / 24rem@container (width>=24rem)
@container(md)448px / 28rem@container (width>=28rem)
@container(lg)512px / 32rem@container (width>=32rem)
@container(xl)576px / 36rem@container (width>=36rem)
@container(2xl)672px / 42rem@container (width>=42rem)
@container(3xl)768px / 48rem@container (width>=48rem)
@container(4xl)896px / 56rem@container (width>=56rem)
@container(5xl)1024px / 64rem@container (width>=64rem)
@container(6xl)1152px / 72rem@container (width>=72rem)
@container(7xl)1280px / 80rem@container (width>=80rem)
@container(8xl)1440px / 90rem@container (width>=90rem)

This is different from viewport breakpoints on purpose. A component threshold is usually smaller than a page threshold. For example, @container(md) can represent a comfortable card width, while @md represents a desktop page shell.


Query container ranges

Use comparison and logical operators when a component needs a bounded range.

<div class="hidden@container(sm&<=md)">...</div>
Generated CSS
@layer utilities {    @container ((width>=24rem) and (width<=28rem)) {        .hidden\@container\(sm\&\<\=md\) {            display: none        }    }}

Prefer named container tokens for repeated component states. Use raw container query values only when the threshold belongs to one local component and is unlikely to become part of the shared design language.


Use named containers

Use named containers when a descendant should query a specific ancestor instead of the nearest container.

<section class="container:card/inline-size">    <article class="grid-cols:2@card(3xs)">...</article></section>
Generated CSS
@layer utilities {    .container\:card\/inline-size {        container: card/inline-size    }    @container card (width>=16rem) {        .grid-cols\:2\@card\(3xs\) {            display: grid;            grid-template-columns: repeat(2, minmax(0, 1fr))        }    }}

Named containers are useful in nested layouts, but do not add names everywhere. The default nearest-container behavior is simpler and easier to move between compositions.


Choose caps or queries

Container size values and container queries are related, but they solve different problems.

NeedUseExample
Cap a page wrapperContainer valuew:full max-w:7xl mx:auto
Cap a content measureLocal or container valuemax-w:72ch or max-w:5xl
Adapt a reusable componentContainer querygrid-cols:2@container(md)
Coordinate nested responsive regionsNamed containergrid-cols:2@card(3xs)
Change the whole page shellBreakpointgrid-cols:12@md

A reusable card depends on the viewport, so it changes at the wrong time inside narrow parents.

<article class="grid-cols:2@md">...</article>

The card depends on the space it receives.

<section class="container">    <article class="grid-cols:2@container(md)">...</article></section>

If a layout rule describes the whole page, use breakpoints. If it describes a reusable component or a wrapper width, use containers.


  • Master UI


© 2026 Aoyue Design LLC.MIT License
Trademark Policy