A card in a narrow sidebar and the same card in a wide main column should both look right.
Direct answer
Container queries apply styles based on the size of a container element. Mark a parent with container-type: inline-size, then use @container (min-width: ...) to change its children. They make components reusable wherever they are placed.
Example
.card-wrap {
container-type: inline-size;
}
.card {
display: grid;
gap: 12px;
}
@container (min-width: 480px) {
.card {
grid-template-columns: 160px 1fr;
}
}
<div class="card-wrap">
<article class="card">
<img src="a.jpg" alt="">
<div>Text</div>
</article>
</div>
When to use
- Reusable components placed in different contexts.
- Design systems.
When media queries are better
- Page-level layout decisions.
- User preferences like dark mode.
Where Teyro fits
Teyro's Responsive Web Design with CSS course turns this into short lessons you can play in a few minutes a day. It has 100 lessons, and you can start free.
The bottom line
Media queries for the page, container queries for components.



