Container Queries in CSS
From the CSS cheat sheet ยท Media Queries & Responsive ยท verified Jul 2026
Container Queries
Style components based on their container size, not the viewport
css
.card-wrapper {
container-type: inline-size;
}
@container (min-width: 400px) {
.card { display: flex; gap: 1rem; }
}
@container (min-width: 600px) {
.card { font-size: 1.25rem; }
}๐ก Container queries let components adapt to where they are placed, not just viewport size
โก The same .card component can have different layouts in a sidebar vs main content area
๐ Set container-type: inline-size on the parent โ then @container queries check ITS width
๐ข Container query units (cqi, cqb) are like vw/vh but relative to the container
container-queriesresponsivecomponents