container-type and container-name
Define query containers using container-type and give them names with container-name.
What are Container Queries?
Container queries allow CSS to apply styles based on the size of a parent container rather than the viewport. This enables truly component-based responsive design where a component adapts to wherever it is placed.
The Problem Container Queries Solve
With media queries, a card component in a 300px sidebar cannot know it is small — it only knows the viewport is wide. Container queries let the component react to its own container's size, not the global viewport.
All lessons in this course
- container-type and container-name
- @container Rules and Breakpoints
- Container Query Units: cqw cqh
- Container Queries vs Media Queries