Stop Treating CSS Container Queries Like Traditional Media Queries
Our take

The recent article highlighting the underutilization of CSS Container Queries strikes a chord, echoing a common pattern in technology adoption – the initial skepticism and slow uptake of genuinely useful features. It's understandable; many developers, like the author admits, initially questioned the need for container queries when media queries have served us for so long. The initial reaction – “Why do I need this?” – is a sentiment many of us have likely felt when confronted with a seemingly incremental advancement. However, dismissing them out of hand overlooks a fundamental shift in how we approach component design and reusability, a concept particularly relevant as AI tools increasingly generate and manipulate code. Considering the broader landscape of AI-driven development, the efficiency gains from embracing container queries become even more compelling. As we see with the release of TabPFN-3.5 [TabPFN-3.5 is released as the next SOTA tabular foundation model [N]], the drive toward optimizing and streamlining development processes is accelerating. Container queries directly contribute to that goal.
The core distinction, as the article rightly points out, lies in the context. Media queries react to characteristics of the *viewport* – screen size, orientation, etc. – while container queries respond to the size of a *containing element*. This seemingly subtle difference unlocks a level of adaptability previously difficult to achieve. Think of a card component: with media queries, you’d need separate CSS rules for various screen sizes. With container queries, that same card component can dynamically adjust its layout based on the space available within its parent container, whether that's a narrow sidebar or a wide dashboard panel. This is especially crucial in a world where components are increasingly designed to be modular and reusable across diverse layouts. The trend toward smaller, more focused AI models, like the recent release of a 44M parameter quantized LLM [I trained a 44M parameter quantized LLM from scratch on 45B tokens. [P]], underscores the value of efficient, adaptable code – principles directly served by container queries. It’s not about replacing media queries entirely, but about strategically choosing the right tool for the job.
The slow adoption rate, despite near-universal browser support, suggests a need for better education and practical examples. Developers are often hesitant to adopt new technologies without clear demonstration of their value and ease of implementation. The initial learning curve can be steep, and the perceived complexity often outweighs the immediate benefits. Furthermore, the current infrastructure for AI-powered code generation and modification may not yet fully leverage container queries, potentially creating a feedback loop where their utility remains underappreciated. As data center energy consumption continues to rise, as highlighted by the analysis of U.S. data centers [US data centers could consume more natural gas than Germany and Japan combined by 2035], optimizing code efficiency becomes an increasingly important consideration, and container queries offer a valuable pathway towards that goal. A more streamlined approach to styling, reducing the need for verbose and repetitive CSS, can contribute to smaller file sizes and faster load times, all of which contribute to a more sustainable web.
Ultimately, the rise of container queries represents a move towards a more flexible and component-centric web development paradigm. While media queries will undoubtedly remain relevant for broader viewport-level adjustments, container queries empower developers to create truly reusable components that adapt seamlessly to their surrounding context. The question now is not *if* container queries will become mainstream, but *how quickly* developers will fully integrate them into their workflows and leverage their potential to build more efficient, adaptable, and maintainable applications – a shift that will be increasingly important as AI continues to reshape the landscape of software development.
To be completely honest with you, I missed the news when CSS Container Queries first shipped. And when I finally heard about it, my very first thought was, “Why exactly do I need this when media queries already exist?”
I’m not proud of that reaction, knowing what I know now, but it was comforting to know that I wasn’t alone. In fact, there are legions of us out there.
What baffles me is that container queries aren’t a new feature, as it currently sits at around 94% browser support. And yet, very few people are actually using it. According to the State of CSS survey, 86% of developers are aware of container queries, but only 41.4% actually use them. Surveys can be biased and not completely representative of our entire field, but this one is certainly the best indicator we’ve got.
Kevin Powell also talked about this at SmashingConf Amsterdam 2026: Container Queries adoption has been terrible. And that is so strange to me, knowing that the ability for components to adapt to the size of their outer container has been at the top of so many CSS wishlists over the years.
I’m not particularly interested in how many people are using container queries as much as in how they are using them. I can’t account for everyone, but from what I’ve seen — including in my own early attempts — many of us are using them wrong.
The bottom line is that incorrect use comes down to the same impression I had when learning about them: they absolutely look just like media queries at first glance. And since they look similar, it’s easy to assume they serve similar purposes and work the same way.
They don’t.
Note: I should state up front that what I’m focusing on in this article is using container size queries, i.e., a responsive design technique for responding to the size of a particular container. There are also container style queries that respond to a container’s computed styles (and are experimental at the time of this writing). You can catch up on those in Juan Diego’s piece here on Smashing Magazine where he examines their possible use cases.
Media Queries Look OutwardThe viewport is a proxy. It always has been. Media queries are what gave us the illusion that screen width alone is responsible for how responsive apps adapt to their environment.
Ask yourself this: When you write @media, what are you asking the browser?
@media (min-width: 1024px) {
.card {
display: flex;
}
I, like most developers, am asking the browser: How wide is the screen right now? That’s it.
Media queries answer that beautifully, but what happens when this .card component is placed in a grid cell that’s 300px wide on a 1920px desktop screen?
The media query doesn’t care; it does its job. The viewport is still 1920px, so min-width: 1024px fires and the matched query styles are applied, even though the card only has 300px of space to work with. Eventually, everything in the card deforms, overflows, or cramps up.
“Media queries are dumb. Not dumb in terms of the concept, but dumb in that they don’t know very much. In fact, most people assume that they know more than they do.”
— Kevin Powell
It’s common to think of responsive design purely as a system for updating complete page layouts, like going from two columns on a large screen to a single column on a small screen.
Container Queries Look InwardContainer queries are smarter than that. They make responsive layouts more reliant on what’s happening inside a component rather than on the outer context that has no insight into a component’s contents. It is more like: “How much space is available for me in this specific spot, right now?”
Here is the same card code example we looked at in the last section, but with a container query:
.card-wrapper {
container-name: card;
container-type: inline-size;
}
@container card (min-width: 450px) {
.card {
display: flex;
flex-direction: row;
}
}
This changes everything. The card isn’t influenced by the viewport; its only concern is whether the .card component’s parent wrapper has at least 450px of inline (i.e., horizontal in a left-to-right writing mode) space. If that condition is true, the component goes horizontal; if not, it goes to its default block display.

The logic works like this:
- When there’s enough room, both items (
.flex-item) sit side-by-side, each exactly half the parent container’s width. - When there is limited space, the second item wraps to the next line.
- Because
flex-growis active on each item, the wrapped items stretch to fill most of the parent’s width. - If the item is a container itself, it detects the sudden width expansion and fires.
/* The flex parent */
.flex-layout {
display: flex;
flex-wrap: wrap;
}
/* Register a flex item as a container */
.flex-item {
container-type: inline-size;
flex: 1 1 390px; /* Grow to fill space, wrap at 390px */
}
/* Default Card Styles (narrow / side-by-side) */
.card {
display: flex;
flex-direction: column;
background: #f4f4f4;
}
/* Once there's enough room for a full row */
@container (min-width: 600px) {
.card {
flex-direction: row;
align-items: center;
background: #e2f0d9;
}
}
This works. As the parent size shrinks and the cards wrap to two lines, the card item expands, the container query fires, and applies the necessary styles.

At the end of the day, the core reason why container queries look incredibly similar to media queries is simply familiarity. They’re not exactly “new”, but they are way less understood and adopted than media queries. But media queries have plenty of their own limitations; otherwise, we wouldn’t need container queries to fill those gaps.
What we have is a more effective feature for detecting when a specific component’s context changes and a means for adjusting styles based on its content, as it should be when that component can exist in multiple contexts.
Read on the original site
Open the publisher's page for the full experience