Media queries sense the "viewport", while container queries sense "the parent container the component itself lives in" — so the same component renders appropriately whether it is placed in a narrow sidebar column or a wide main-content column. This is true "component-level responsiveness".
The Limits of Media Queries
Imagine a card component that may appear in a three-column grid or in a single-column sidebar. Media queries only know how wide the browser viewport is; they do not know how much space this card actually has available at the moment — that is exactly the problem container queries solve.
Tipcontainer-type: inline-size means the container only listens for size changes along the inline axis (usually width) — the most common and best-performing value.
Container-relative Units
Alongside container queries, CSS provides a set of relative units that let font-size and spacing scale smoothly with the container, instead of jumping abruptly at breakpoints:
Unit
Meaning
cqw
1% of the container's width
cqh
1% of the container's height
cqi
1% of the container's inline size
cqb
1% of the container's block size
.card h3 {
font-size: clamp(16px, 4cqi, 22px);
}
Container Style Queries
Going further, you can also decide child-element styles based on the container's own custom-property values, enabling "the theme follows the container":