New series: what assistive tech really hears on your checkout page. Start with part one →
Shipwright
Home
CSS Aug 16, 2026 2 min read 152 views

Container Queries Explained with One Resizable Component

Mara Okafor

Mara Okafor

@maraokafor

Share
Cover illustration for the article Container Queries Explained with One Resizable Component

A single card component, resized live, reacting to its container instead of the viewport. Most CSS problems we see in reviews are not about a missing property. They are about a layout that was never told what it should do when the content changes size, and that is what this piece sets out to fix.

Sample footage: a CC0 clip from the MDN Web Docs example media.

Start from the constraint

Begin by writing down the smallest and largest sizes the component must survive. Once those two numbers exist, properties such as clamp(), minmax(), and fit-content stop feeling like magic and start reading like a specification.

  • Set explicit minimum and maximum sizes first.
  • Prefer intrinsic sizing keywords over fixed pixel values.
  • Let the container decide, not the viewport.
  • Keep one fallback declaration above the modern one.

The tricky part is always the middle: the tablet widths nobody designs for, the translated label that is forty percent longer, the avatar that failed to load. Test those states on purpose by resizing the container rather than the whole window.

None of this is new, and that is the point. The techniques that last are usually the boring ones that are documented well and supported by the platform itself.

As always, the examples are simplified to fit on a page. The production version has more error handling and logging, but the shape of the code is the same.

Questions, corrections, and war stories are welcome in the comments. Several of our best follow-up posts started as a reader pointing out something we had missed.

The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.

Tim Berners-Lee, W3C Web Accessibility Initiative launch, 1997

Mara Okafor

Mara Okafor

Author

Staff frontend engineer focused on CSS architecture and accessibility. Mara has audited more design systems than she can count and still gets excited about a good focus ring.

Related Posts

Comments 0

Leave a comment

Your email will not be published. Sign in for a faster experience.

Supports **bold**, *italic*, and `code`.