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, andflex-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.
| Token | Value | PX | Description |
|---|---|---|---|
--container-3xs | 16rem | 256px | Small component, compact card, or narrow popover. |
--container-2xs | 18rem | 288px | Compact panel and constrained media region. |
--container-xs | 20rem | 320px | Small content module or sidebar-friendly component. |
--container-sm | 24rem | 384px | Comfortable card, form block, or narrow reading panel. |
--container-md | 28rem | 448px | Common component layout threshold. |
--container-lg | 32rem | 512px | Wide component or compact page section. |
--container-xl | 36rem | 576px | Large section, modal, or media composition. |
--container-2xl | 42rem | 672px | Small page wrapper or large split-pane region. |
--container-3xl | 48rem | 768px | Compact page canvas. |
--container-4xl | 56rem | 896px | Standard page canvas. |
--container-5xl | 64rem | 1024px | Reading or documentation wrapper. |
--container-6xl | 72rem | 1152px | Wide content wrapper. |
--container-7xl | 80rem | 1280px | Maximum product canvas. |
--container-8xl | 90rem | 1440px |
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.
| Group | Utility keys | Description |
|---|---|---|
| Preferred size | w, h, width, height, inline-size, block-size, size, size-x, size-y | Set one axis or both axes from the shared container scale. |
| Minimum constraints | min, min-w, min-h, min-size, min-size-x, min-size-y, min-width, min-height, min-inline-size, min-block-size | Keep regions from collapsing below a reusable layout threshold. |
| Maximum constraints | max, max-w, max-h, max-size, max-size-x, max-size-y, max-width, max-height, max-inline-size, max-block-size | Cap wrappers, panels, media, and content regions. |
| Layout basis | flex-basis | Give flex items a shared starting size before free space is distributed. |
| Intrinsic and media sizes | background-size, mask-size, contain-intrinsic-inline-size, contain-intrinsic-block-size | Use 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.
| Value | Token | Size | Example utility |
|---|---|---|---|
3xs | container-3xs | 256px / 16rem | max-w:3xs |
2xs | container-2xs | 288px / 18rem | max-w:2xs |
xs | container-xs | 320px / 20rem | max-w:xs |
sm | container-sm | 384px / 24rem | max-w:sm |
md | container-md | 448px / 28rem | max-w:md |
lg | container-lg | 512px / 32rem | max-w:lg |
xl | container-xl | 576px / 36rem | max-w:xl |
2xl | container-2xl | 672px / 42rem | max-w:2xl |
3xl | container-3xl | 768px / 48rem | max-w:3xl |
4xl | container-4xl | 896px / 56rem | max-w:4xl |
5xl | container-5xl | 1024px / 64rem | max-w:5xl |
6xl | container-6xl | 1152px / 72rem | max-w:6xl |
7xl | container-7xl | 1280px / 80rem | max-w:7xl |
8xl | container-8xl | 1440px / 90rem | max-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.
| Variant | Value | Generated 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.
| Need | Use | Example |
|---|---|---|
| Cap a page wrapper | Container value | w:full max-w:7xl mx:auto |
| Cap a content measure | Local or container value | max-w:72ch or max-w:5xl |
| Adapt a reusable component | Container query | grid-cols:2@container(md) |
| Coordinate nested responsive regions | Named container | grid-cols:2@card(3xs) |
| Change the whole page shell | Breakpoint | grid-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.