container query
A CSS rule, written with @container, that styles a component based on the size of its container instead of the whole viewport.
In more detail
An ancestor becomes a query container with container-type: inline-size. Rules inside @container (min-width: 400px) then react to that container's width, so the same card lays out differently in a narrow sidebar and a wide main column.
Related terms
- container-type — The CSS property that turns an element into a query container that its descendants can run container queries and container units against.
- container query units — CSS length units measured against the query container: 1cqi is one percent of its inline size, 1cqw of its width, 1cqh of its height.
- media query — A CSS rule, written @media, that applies styles only when a condition about the device or user settings is true.
- component-driven design — Designing layouts so each component adapts to the space it is given, not to the screen size, so it works wherever it is placed.
Taught in
- Container Queries: Component-Driven Responsive Design — Frontend Architecture & Web Platform