Notes on building for the open web.
Home / Articles / CSS

Container queries in production

CSS

Container queries let a component respond to the width of its parent. That sounds like a small change until you put the same card in a narrow sidebar and a wide main column; the card can now adapt without a page-level media query.

Name containers deliberately. A generic name is easy to reuse by accident, and a component that queries the wrong container is hard to debug. Prefer names that describe the role, such as card-shell or article-body.

Start with one breakpoint per component and add another only when the content actually breaks. Container queries make it tempting to add many small variants; restraint keeps the CSS readable.

Test in both extremes. A component that feels native in a wide column and cramped in a sidebar is not finished; the same component should feel intentional in both.