Capítulo 9 de 29
@container marks an element as a query container so its descendants can be styled with @sm:/@md:-style variants based on that container's own size, not the viewport — making components portable and reusable regardless of where they're placed in a layout.
@container class to a wrapper; its children can then use @{size}: variants (@md:flex-row) to respond to that container's width, mobile-first (applies at that size and up) just like viewport breakpoints.@max-sm:, @max-md:, etc. apply below a given container size — the container-query equivalent of max-* breakpoint variants.@sm:@max-md:flex-col) to scope a style to a specific container-size window.@container/{name} names a container so nested content can target a specific ancestor container instead of the nearest one, via @sm/{name}: — needed when containers are nested and you must reach past the closest one.@container alone only tracks inline-size (width). Use @container-size when you need container query units that depend on block-size too (e.g. h-[50cqb]); also nameable (@container-size/{name}).cqw/cqi (and cqb/cqh with a size container) can be used directly as arbitrary values in any utility (w-[50cqw]), not just inside @container variants.--container-* theme variables (@theme { --container-8xl: 96rem; }) add new named container-size variants (@8xl:), same mechanism as --breakpoint-*.@min-[475px]:/@max-[960px]: for one-off sizes not worth adding to the theme.<div class="@container">
<div class="flex flex-col @md:flex-row @sm:@max-md:flex-col">
</div>
</div>
<div class="@container/sidebar">
<div class="@sm/sidebar:flex-row">
</div>
</div>
| Variant | Min container width | Variant | Min container width | |
|---|---|---|---|---|
@3xs | 16rem (256px) | @2xl | 42rem (672px) | |
@2xs | 18rem (288px) | @3xl | 48rem (768px) | |
@xs | 20rem (320px) | @4xl | 56rem (896px) | |
@sm | 24rem (384px) | @5xl | 64rem (1024px) | |
@md | 28rem (448px) | @6xl | 72rem (1152px) | |
@lg | 32rem (512px) | @7xl | 80rem (1280px) | |
@xl | 36rem (576px) |
@container alone is inline-size-only — add @container-size only when you specifically need block-size-dependent units (cqb/cqh).@container/name) are the escape hatch for nested containers where the default "nearest ancestor" targeting isn't the one you need.--container-* variables follow the same @theme customization pattern as --breakpoint-*.