CSS Container Queries Are Ready for Production. Here's How to Use Them.
Container queries let components respond to their container's size, not the viewport. After two years of browser support maturation, here's how to use them today.
The component responsiveness problem has been a thorn in frontend developers' sides since responsive design became standard. Media queries work for page layouts but they're terrible for components that appear in different contexts.
Container queries solve this. And in 2025, they're ready to use without apology.
The Setup: Container Type
You define a containment context on the parent element, then write queries that respond to it:
The container-type: inline-size establishes the query context. Without this, @container rules won't work.
A Real Example: A Card That Adapts
Imagine a product card that should be compact in a sidebar (200px wide) and expanded in the main grid (350px wide), without any JavaScript or extra props.
Drop this card anywhere. In the sidebar it stacks. In the main grid it goes horizontal. No media queries, no JavaScript, no prop drilling.
Using cqi Units for Responsive Type
The heading scales from 1rem minimum to 1.75rem maximum, proportional to the container width. Works everywhere the card appears without any tweaking.
When to Keep Using Media Queries
Container queries don't replace media queries — they complement them. Use media queries for page-level layout decisions: sidebar visible or not, one-column vs three-column grid, navigation collapsed or expanded. Use container queries for component-level adaptation: how a card looks at different widths, how a button group wraps, how typography scales. The mental model: media queries for structure, container queries for components.
Frequently Asked Questions
What's the difference between media queries and container queries?+
Do container queries have good browser support now?+
What is a container query unit?+
Can I use container queries for things other than size?+
🔧 Free Tools Used in This Guide
FreeToolKit Team
FreeToolKit Team
We build free browser-based tools and write practical guides that skip the fluff.
Tags: