CSS Container Query Builder
Build @container queries — the modern way to create truly component-responsive layouts.
Stacks vertically on narrow, switches to horizontal row on wider containers
Premium Headphones
Noise-cancelling wireless audio
min-width: 260px — compact
CSS
.parent {
container: card / inline-size;
}
/* Narrow: stacked layout */
.card { flex-direction: column; }
/* Medium: compact info */
@container card (min-width: 260px) {
.card { padding: 16px; }
}
/* Wide: horizontal layout with CTA */
@container card (min-width: 380px) {
.card { flex-direction: row; }
.cta { display: block; }
}Shows progressive detail — bio text and follow button appear as space grows
Sarah Johnson
Senior Designer
Passionate about creating beautiful, intuitive interfaces.
CSS
.parent {
container: profile / inline-size;
}
/* Narrow: stacked, no bio */
.profile { flex-direction: column; }
/* Medium: bio text appears */
@container profile (min-width: 280px) {
.bio { display: block; }
}
/* Wide: side-by-side + follow button */
@container profile (min-width: 340px) {
.profile { flex-direction: row; align-items: center; }
.follow-btn { display: inline-flex; }
}Adds trend indicator and sparkline chart as the container expands
Total Revenue
$48,295
CSS
.parent {
container: stat / inline-size;
}
/* Default: number only */
/* Medium: show percentage change */
@container stat (min-width: 240px) {
.trend { display: flex; }
}
/* Wide: show sparkline chart */
@container stat (min-width: 320px) {
.chart { display: flex; }
}Icon-only on narrow containers, adds labels then search bar as width grows
CSS
.parent {
container: navbar / inline-size;
}
/* Narrow: icons only */
.nav-label { display: none; }
.search { display: none; }
/* Medium: show labels */
@container navbar (min-width: 280px) {
.nav-label { display: inline; }
}
/* Wide: show search bar too */
@container navbar (min-width: 360px) {
.search { display: flex; }
}Container Query vs Media Query
@media — Viewport-based
/* Responds to the browser window */
@media (min-width: 768px) {
.card { flex-direction: row; }
}Works for page-level layouts but breaks when the same component is reused in different sized columns.
@container — Component-based
/* Responds to the parent's size */
@container card (min-width: 380px) {
.card { flex-direction: row; }
}The component adapts to wherever it's placed — sidebar, main content, modal — without any changes.