Verdant
Premium botanical
Components that know their own size.
Premium botanical
Premium botanical
Premium botanical extract
Premium botanical extract — crafted from wild-harvested botanicals for a refined, lasting scent.
For years, responsive design meant one thing: watch the viewport. You'd write
@media (min-width: 768px) and hope your component landed in the right
context. But viewport width is a blunt instrument — a sidebar card and a hero card
can occupy the same viewport, yet need completely different layouts.
Container Queries change the contract. Instead of asking "how wide is the window?", a component can ask "how wide is my container?" — and reshape itself accordingly. The component becomes truly self-contained, portable across any layout.
Declares a containment context. inline-size creates a query context for the inline axis. size covers both axes.
Assigns an identifier so nested queries can target a specific ancestor — essential when containers are nested inside one another.
The query itself. Works like a media query but uses the nearest containment ancestor as the source of truth for its conditions.
cqi, cqb, cqw, cqh — percentage units relative to the query container's dimensions. Like vw but local.
Set up a containment context on the parent, then query it from within the component.
/* 1. Declare the containment context */
.card-container {
container-type: inline-size;
}
/* 2. Style the card based on container width */
@container (min-width: 500px) {
.card {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 1.5rem;
}
}
When containers are nested, name them so the query targets the right ancestor.
.sidebar {
container-type: inline-size;
container-name: sidebar;
}
.main {
container-type: inline-size;
container-name: main-content;
}
/* Query the named container specifically */
@container sidebar (min-width: 300px) {
.card { font-size: 1rem; }
}
@container main-content (min-width: 600px) {
.card { font-size: 1.25rem; }
}
Use cqi, cqb, cqw, cqh, cqmin, cqmax to size elements relative to their container.
/* cqi = 1% of container's inline size (usually width) */
/* cqb = 1% of container's block size (usually height) */
/* cqw = 1% of container width (physical) */
/* cqh = 1% of container height (physical) */
.card-title {
font-size: clamp(1rem, 4cqi, 3rem);
padding: 2cqi;
}
.card-image {
width: 30cqi;
height: 30cqi;
}
Drag the handle to resize the container and watch the card morph through its breakpoints in real time.
Premium botanical extract — crafted from wild-harvested botanicals for a refined, lasting scent.
/* Drag the resize handle above
to see which @container rules
are active at the current width */