Short answer
Container queries apply styles from a container's size, name, or other state, instead of from the viewport. You mark an element with container-type, then write an @container rule for its descendants. MDN's guide shows a card whose title grows when the container is wider than 700px. MDN marks the at-rule and the property Baseline Widely available since February 2023, with a note that some parts vary.
Last verified against the sources listed below.
Key takeaways
- A container query looks at an ancestor you named or sized, not at the browser window.
- container-type: inline-size is the usual switch for width-based queries.
- size also contains the block axis. normal does not opt in to size queries.
- The 30 October 2025 conditional draft adds scroll-state. MDN also lists anchored.
- MDN says @container and container-type have been widely available since February 2023.
- If a size container has no explicit or contextual size, MDN says it collapses.
What are container queries is a CSS question about styling descendants from an ancestor you choose, not from the window. MDN’s guide says they can depend on the container’s name, its size, styles applied to it, its scroll state, or an anchor-position fallback. Size queries are the part that guide walks through.
Responsive web design still starts from the viewport. A container query is the extra test for a component that moves between columns.
CSS is the language both tests are written in. The property and the at-rule below are the two pieces MDN asks you to set.
What does @container check?
@container applies the rules inside it only when a condition is true for a query container. MDN calls it a conditional group rule. The condition is rechecked when the container’s size, a style feature, or scroll state changes. You can pass a container name, a query, or both.
A size test from the guide looks like this. The heading stays at 1em until the container’s width passes 700px, which is MDN’s sample, not a required breakpoint.
.card h2 { font-size: 1em; }
@container (width > 700px) {
.card h2 { font-size: 2em; }
}
With a name, the same guide writes @container sidebar (width > 700px). A name-only rule has no parentheses test. It styles elements that sit inside an ancestor with that container-name.
The conditional rules draft of 30 October 2025 defines @container as a conditional group rule whose condition is a container query. The syntax it prints includes a parenthesized size feature, style(), and scroll-state(). MDN’s at-rule page also shows an anchored() example. That named form is not in the grammar lines quoted here from the October 2025 draft.
What values does container-type take?
container-type decides which queries the element can answer. MDN’s property page lists normal, size, inline-size, scroll-state, and anchored. A two-value form must pair scroll-state with either size or inline-size.
| Value | What MDN says it establishes | Containment MDN attaches |
|---|---|---|
| normal | Not a size, scroll-state, or anchored container. Style and name-only queries still work | None for those size queries |
| inline-size | Dimensional queries on the inline axis | Style and inline-size containment |
| size | Size queries on both the inline and block axes | Style and size containment |
| scroll-state | Scroll-state queries. Size is not computed in isolation | No containment |
| anchored | Anchored queries. Size is not computed in isolation | No containment |
The October 2025 draft’s value line is normal | [ [ size | inline-size ] || scroll-state ]. The initial value is normal, and the property is not animatable.
size and inline-size also establish an independent formatting context in that draft. anchored is on MDN’s page and is not in that draft’s value line, as of the copies read in December 2026.
An older copy still matters if you hit it in a search. The containment Level 3 Working Draft of 18 August 2022 defined container-type as normal or size or inline-size only.
The editor’s draft dated 22 December 2025 says the property’s definition moved to the conditional rules module. Read the 2025 conditional draft, or MDN, for the current list, rather than stopping at the 2022 value line.
How do the length units work?
When container-type is size or inline-size, MDN says descendants can use container query length units. Each unit is 1% of a container measurement.
cqwis 1% of the query container’s width.cqhis 1% of its height.cqiis 1% of its inline size.cqbis 1% of its block size.cqminis the smaller ofcqiandcqb.cqmaxis the larger of the two.
If no eligible container exists, MDN says the unit falls back to the small viewport unit on that axis. The guide’s sample mixes a floor with cqi: max(1.5em, 1.23em + 2cqi), inside a width query. A px to rem converter only changes a length’s unit. It does not create the container.
Where does support stand, as of December 2026?
MDN’s @container page and its container-type page both say the feature is well established and has been available across browsers since February 2023. Both carry an asterisk that some parts may have varying support. The indicator marks Chrome, Edge, Firefox, and Safari supported. This article stops there, because that is the support text on those pages.
The guide’s fallback, for browsers that do not support the queries, is ordinary grid or flex, plus a media query if you still want a viewport test. That is a layout fallback, not a second support table.
What mistake collapses the box?
Setting container-type: size without giving the element a size is the miss MDN warns about. Size containment stops the children from defining the size, so a query cannot chase its own result. If the width is not coming from the parent, as a block box often does, or from an explicit length, the box collapses.
A second miss is expecting the HTML default stylesheet to create a container. The rendering section expects div, p, and a list of other elements to be display: block.
That expected rule is not container-type. A block box can be a size container only after you set the property. Until then, @container (width > 700px) has nothing to measure on that element.
The shorthand container: sidebar / inline-size is the compact way to set the name and the type together. The type is what opts the element into size queries. The name is how a rule finds that element when several containers are nested.
Frequently asked questions
Are container queries the same as media queries?
No. MDN's container-query guide says media queries apply styles from viewport size or other device characteristics. Container queries apply styles from attributes of a container: its name, its size, styles on it, its scroll state, or whether it is anchor-positioned and using a position-try fallback. A card can sit in a sidebar and in a main column and pick up different rules without a new viewport breakpoint. The viewport can stay wide while the card's column is narrow.
What does container-type: inline-size do?
On MDN, inline-size makes the element a query container for dimensional queries on the inline axis, and it applies style containment and inline-size containment. The inline size can be computed without looking at the children. The CSS Conditional Rules draft of 30 October 2025 says the same value establishes size queries on the container's own inline axis and establishes an independent formatting context. normal, the initial value, does not make the element a size container.
Can I name the container?
Yes. MDN shows container-name set to a custom ident such as sidebar, then an at-rule written as @container sidebar (width > 700px). A name-only rule, with no size test, applies to elements that have an ancestor with that name. The shorthand on the same guide is container: sidebar / inline-size, name first, then the type. If you omit the name, MDN says the size features are tested against the nearest ancestor whose container-type matches.
Which browser versions does MDN list?
The @container page and the container-type page, as read in December 2026, both say the feature is Baseline Widely available and has been available across browsers since February 2023. Both add an asterisk: some parts may have varying levels of support. The status indicator on those pages marks Chrome, Edge, Firefox, and Safari as supported. This article does not add per-browser version numbers, because those pages' summary text does not print them.
Why did my size container collapse?
MDN's container-type page says size containment turns off the element's ability to take its size from its contents, which stops a query from looping. The rule inside the query could change the content size, which would change the query, which would change the size again. If nothing else sets the size, a contextual width or an explicit length, MDN says the element collapses. Block-level boxes that stretch to the parent are one contextual case.
Sources
- CSS container queries · MDN Web Docs, 2026
- @container · MDN Web Docs, 2026
- container-type · MDN Web Docs, 2026
- CSS Conditional Rules Module Level 5 · W3C, 2025
- CSS Containment Module Level 3 · W3C, 2022
- CSS Containment Module Level 3, Editor's Draft · CSS Working Group, 2025
- HTML Standard, rendering · WHATWG, 2026