Master Modern CSS
Learn everything from basics to advanced techniques including Container Queries, :has(), and more!
Search all CSS Showcase pages by name
Finally! Components that respond to their container's size, not the viewport. Build truly reusable components that work anywhere.
Container queries allow you to apply styles based on the size of a containing element rather than the viewport. This means your components can adapt to any layout context — sidebar, main content, or anywhere else!
/* Responds to viewport only */
@media (min-width: 768px) {
.card {
display: grid;
grid-template-columns: 200px 1fr;
}
}
/* Problem: Card looks wrong in sidebar! *//* Responds to container size */
.card-container {
container-type: inline-size;
}
@container (min-width: 400px) {
.card {
display: grid;
grid-template-columns: 200px 1fr;
}
}These demos use real CSS container queries. Resize the containers to see how the same component adapts to different sizes.
Learn everything from basics to advanced techniques including Container Queries, :has(), and more!
Learn everything from basics to advanced techniques including Container Queries, :has(), and more!
This text scales with container width!
Components adapt to container styles!
Same component, different container style
Understanding when to use each approach is key to building robust responsive systems.
See how container queries transform real interface patterns. The same article component adapts seamlessly between main content and sidebar contexts.
Container queries revolutionise how we build responsive components...
“Container queries are the most requested CSS feature for over a decade!”
They finally allow us to create truly reusable components.
Keep these guidelines in mind when using container queries in production.
Use inline-size for horizontal queries, size for both dimensions. Most components only need inline-size.
Container queries have minimal performance impact. The browser optimises them efficiently — no need to worry about overhead.
Always provide sensible defaults. Container queries should enhance, not break, your layout. Use @supports where needed.