How do you design responsive components without hard-coding every viewport?
Use fluid constraints, intrinsic layout, content-driven breakpoints, and container queries where appropriate.
A component does not always know how wide the screen is, and it often does not need to. A card inside a sidebar has less room than the same card on a full-width page. Container queries let the component respond to the space its parent gives it, while media queries remain useful for changes tied to the viewport.
A component does not always know how wide the screen is, and it often does not need to. A card inside a sidebar has less room than the same card on a full-width page. Container queries let the component respond to the space its parent gives it, while media queries remain useful for changes tied to the viewport.
The quick version
Prefer layouts that adapt intrinsically, then add breakpoints when the composition genuinely changes. Container queries let a component respond to the space it receives rather than the viewport alone.
Build the mental model
A viewport breakpoint answers “how wide is the screen?” A container query answers “how much space does this component have?” Fluid functions such as clamp() interpolate within bounds.
See it in code
.card-grid {
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}
.card-title {
font-size: clamp(1.1rem, 2vw, 1.6rem);
}
Where it gets tricky
A component can be narrow inside a wide viewport—for example, in a sidebar or split pane—so viewport-only media queries cannot describe its available space. Container queries solve that local constraint. Still test at 200% zoom and with text enlargement: a layout that only works at common device widths is not truly responsive.
A common misunderstanding
Responsive design is not a set of device-specific widths.
What this changes in an application
Test content extremes, localization, browser zoom, and nested layouts. Container queries are especially useful for reusable cards and embedded panels.
Questions worth exploring next
- When would you use
auto-fitversusauto-fill? - What does
container-type: inline-sizeestablish?
References and next steps
- Responsive design — primary or authoritative documentation for the underlying behavior.
- MDN Web Docs — use the relevant API reference for adjacent browser details.