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

More CSS tasks

Back to the full CSS cheat sheet