DEV Community


Posted on

Explain container queries like I'm five

I've come across many article talking about it but I need some enlightenment. Help

Top comments (2)

facundocorradini profile image
Facundo Corradini • Edited

It's pretty much the same idea as media queries, only based on the container width instead of the viewport size.

The idea is to build responsive components that can be reused in different webs/apps that might serve them in a great variety of layouts.

There are some concerns like circular dependencies that are preventing CSS from building that kind of stuff, but the CSS working group is already proposing some solutions that we might enjoy in the future.

As for right now, for some simple things we can get away with using the flex-grow:9999 hack or some of grid's repeat(auto-fit, minmax()) magic. For more complex stuff, the best approach so far is using a little bit of JS with the Intersection Observer API, as Philip Walton's Responsive Components

rnrnshn profile image

Ohhh. Seems amazing... Thanks...