Caffeinated Coder
Book an appointment
Lesson 12 · Layout

Container queries

A media query asks how wide the browser window is, so a card gets the same answer whether it sits in a narrow sidebar or a wide main column. A container query asks the card's own container instead. Follow one card used in a 250px sidebar and a 700px main column of a 1000px page: mark each slot with container-type: inline-size, let each card ask @container (min-width: 400px), and watch only the card with room go side by side. Then widen the sidebar to 450px without touching the window, and see its card switch too.

10 min7 steps5 questionsIntermediate
Fig 12 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.