Name-only @container queries without size conditions
Container queries without size conditions
Until recently, @container always needed a size condition. To target a named context without caring about size, you wrote @container sidebar (width > 0). Browsers now accept the name on its own.
The old hack vs the modern fix
View demo.sidebar {
container-name: sidebar;
/* a size condition only matches on a size container */
container-type: inline-size;
}
.card {
display: grid;
}
/* size condition required even when you only care about the name */
@container sidebar (width > 0) {
.card {
grid-auto-flow: column;
}
}.sidebar {
container-name: sidebar;
}
.card {
display: grid;
}
@container sidebar {
.card {
grid-auto-flow: column;
}
}
/* no dummy size condition */<!-- mark the parent as a named container --><div class="@container/sidebar"><!-- card flips to row when inside the named container --><div class="grid @min-[0px]/sidebar:grid-flow-col">card content</div></div>Container name queries browser support
Name-only @container queries shipped across all three engines by May 2026 (Chrome 148, Safari 26.4, Firefox 149). Older browsers skip the rule, so keep the default layout usable on its own.
Live demo
Why the modern way wins
No more dummy condition
The pattern @container sidebar (width > 0) existed only to satisfy the parser. Drop the parentheses entirely now.
Context-only styling
Use it when a component should behave differently inside a named ancestor, regardless of size. Cards in a sidebar, items in a modal, anything with shared layout context.
Composes with size queries
You can still chain a size condition when you want one. @container sidebar (width > 400px) remains valid. Drop it when context is the only thing you care about.
- Key Change
- Optional size
- Name alone is enough
- Old Approach
- @container name (width > 0)
- Dummy condition required
- Modern Approach
- @container name
- Name-only query
How it works
The @container rule originally required both a name and a condition. To target a named context without a real size threshold, the workaround was to write a condition that always passed, like (width > 0) or (min-width: 1px). The parens were ceremony, not logic.
The updated grammar makes the condition optional. @container sidebar { ... } now applies styles whenever the matched element is inside a container named sidebar, with no size check at all. It is the cleaner way to express "only when this component lives inside this context".
Pair it with size-based container queries when both matter. The name-only form is purely about scoping styles to a named ancestor.