Overview
A container query lets a component restyle itself from its parent’s size instead of the window’s, so one card renders correctly in a 240px sidebar and an 800px column with no conditional class strings. Size container queries have been Baseline widely available since August 2025. The umbrella page is css.
Query the container, not the viewport
Use @container when a component should respond to the space it has. Use @media for conditions about the device or user: viewport structure, touch, print, reduced motion.
.card-slot { container-type: inline-size; }
.card .title { font-size: 1rem; }
@container (min-width: 32rem) {
.card { display: grid; grid-template-columns: 12rem 1fr; }
.card .title { font-size: 1.25rem; }
}A query styles descendants of the container, never the container itself. Put container-type on a wrapper (.card-slot) and style the component inside it.
Declare container-type on the parent
Without it, @container rules match nothing.
inline-size: queries on width; the usual choice.size: queries on width and height; the container needs an explicit block size.normal: not a size container.
A page-level container around the main column can drive nested components. Put container-type on a component wrapper rather than html or body: it applies layout containment, which makes the element the containing block for fixed and absolutely positioned descendants.
Name containers when nesting
An unnamed query matches the nearest ancestor container. Name nested containers so each rule targets the intended level; container: card / inline-size sets name and type together.
.cards-slot { container: cards / inline-size; }
.card-slot { container: card / inline-size; }
@container card (min-width: 24rem) { .card .title { font-size: 1.25rem; } }
@container cards (min-width: 60rem) { .cards { grid-template-columns: repeat(3, 1fr); } }Size inside containers with cqi
cqi is 1% of the container’s inline size; cqb, cqw, cqh, cqmin, and cqmax cover the other axes.
.card .title { font-size: clamp(1rem, 4cqi, 1.5rem); }Let components own their breakpoints
A reusable component declares its container and its queries; the page only places it. The same markup then stacks in a sidebar and spreads in a wide column. Use css-grid for the layout and tailwind-responsive for the @container utility variants.
Check support for newer query types
| Feature | Status (1 Oct 2026) |
|---|---|
| Size queries | Widely available |
Style queries (@container style(...)) | Newly available (May 2026) |
| Name-only container queries | Newly available (May 2026) |
| Scroll-state queries | Limited availability |
Ship size queries without fallbacks. Gate style and scroll-state queries behind @supports or feature checks.
Avoid common pitfalls
- Missing
container-type. The queries silently match nothing. - Wrong ancestor. Nested unnamed containers match the nearest; name them.
sizewithout a block size. The container collapses; useinline-sizeunless you need height queries.- Reordering with
grid-template-areas. Layout changes between queries can desync DOM and visual order; keep focus order sensible (accessibility).