Container queries
Widely availableChrome 105 · Edge 105 · Firefox 110 · Safari 16
Style an element based on the size of its container instead of the whole viewport. A card can switch from stacked to side-by-side wherever it is placed: a sidebar, a grid cell or a full-width row.
Under 380px wide this card stacks. Wider, the image sits beside the text.
.card-slot {
container-type: inline-size;
}
.card {
display: grid;
gap: 12px;
}
@container (min-width: 380px) {
.card {
grid-template-columns: 120px 1fr;
}
}