Responsive Design and Container Queries
Design components for available space, content pressure, zoom, and user preferences.
Responsive design is not a list of device widths. Start with a flexible base, add a breakpoint when the content needs one, and use container queries when a component should respond to its own available space rather than the whole viewport.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.catalog { container: cards / inline-size; }
.card { display: grid; gap: 1rem; }
@container cards (min-width: 42rem) {
.card {
grid-template-columns: 12rem 1fr;
}
}Working rules
- Test content at 200% zoom
- Add breakpoints where layout pressure appears
- Prefer container queries for reusable embedded components
A common mistake
Hiding useful content on small screens is not a responsive strategy; prioritize and reflow it instead.
Guided practice
Name the at-rule used to respond to an ancestor container's size.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.
- Explain the result in one sentence without relying on jargon.