
For nearly a decade, responsive web design relied exclusively on Media Queries (@media). While transformative when first standardized, media queries have a fundamental flaw in the era of component-driven architectures (React, Vue, Web Components): they only know about the viewport.
When you build a reusable <Card> component, you want it to look good whether it's placed in a wide main content area or squished into a narrow sidebar. Using media queries, the card can only react to the size of the browser window, not the size of its actual parent container. This forces developers into writing complex CSS architectures (like BEM modifiers: .card--sidebar) to manually adjust styles based on placement.
Enter CSS Container Queries (@container). In 2026, with universal browser support across all modern rendering engines, Container Queries allow components to query the size of their parent container directly and adjust themselves accordingly.
Interactive frosted glass generator with live Tailwind export
Design modern frosted glass UI with live backdrop-filter sliders, blur, opacity, borders, and copy ready-to-use Tailwind CSS or pure CSS snippets.
Try dragging the Container Width slider below. Notice how the card automatically transforms from a stacked vertical layout into a horizontal media layout as soon as its parent container crosses 420px - completely independent of your actual screen or browser width!
The implementation involves two straightforward steps:
container-type.@container.To establish a containment boundary, apply the container-type property to the wrapper element:
.card-grid {
/* This element is now a queryable container */
container-type: inline-size;
container-name: card-wrapper; /* Optional name identifier */
}
inline-size: Queries the width along the writing mode axis (most common).size: Queries both width and height dimensions.normal: Default state (not a container).You can also use the shorthand: container: card-wrapper / inline-size;
cqi, cqw, cqh)Just as viewport units gave us vw and vh, Container Queries introduce relative units tied directly to the container's computed box size:
cqi: 1% of the query container's inline size (usually width).cqb: 1% of the query container's block size (usually height).cqmin / cqmax: The smaller or larger value of cqi vs cqb.These units unlock fluid typography and spacing that scales smoothly inside any sidebar or widget.
Imagine a newsletter signup widget that you want to drop into three distinct locations:
With media queries, you would need separate classes like .newsletter--sidebar and .newsletter--footer. With container queries, the component handles its own layout transitions internally:
A development team is migrating a large e-commerce site to a component-driven architecture. They have a `ProductCard` component that needs to display differently (e.g., stacked vs. horizontal layout) based on the available width of its parent container, which can vary significantly depending on whether it's in a sidebar, a main product grid, or a carousel. Before 2026, what was the most common, albeit flawed, approach to achieve this responsive behavior for the `ProductCard` component, and what was its primary limitation?
Yes. CSS Container Queries (@container, container-type, and cqi units) have universal baseline support across Chrome, Edge, Safari, Firefox, and mobile browsers since early 2023.
No. The optimal architecture uses @media for macro page layouts (root grid, page margins, global navigation bars) and @container for micro component layouts (cards, lists, modals, widgets).
Container Queries represent the biggest paradigm shift in CSS since Flexbox and CSS Grid. By shifting responsive logic away from the global viewport and into local component boundaries, you build truly modular, plug-and-play UI design systems.
Clean AI CLI logs, build cron expressions, decode JWTs, and calculate chmod permissions offline.

Stop guessing between CSS Grid and Flexbox. Side-by-side comparison of 1D vs 2D layouts with interactive visual demos, responsive alignment rules, and a decision tree.
Read more
Tailwind CSS v4 brings massive performance improvements, a new engine, and zero-configuration setups. Explore the new features and learn how to migrate your existing projects.
Read more
Learn how to master css hardware accelerated animations, the difference between css transform vs opacity, and when to use css spring animations.
Read more