Responsive design
Media queries, fluid units, and modern container queries — building layouts that adapt instead of breaking.
Start with the viewport meta
Without this tag, mobile browsers render at roughly 980px wide and zoom out, so none of your media queries fire correctly.
<meta name='viewport' content='width=device-width, initial-scale=1'>Media queries
/* mobile-first: base styles, then add at wider widths */
.card { padding: 12px; }
@media (min-width: 768px) {
.card { padding: 24px; }
}
/* combinations */
@media (min-width: 768px) and (max-width: 1023px) { }
@media (prefers-reduced-motion: reduce) { * { animation: none; } }| Feature | Typical use |
|---|---|
min-width/max-width | Layout breakpoints |
prefers-color-scheme | Dark mode defaults |
prefers-reduced-motion | Accessibility: drop animation |
pointer: coarse | Touch-friendly target sizes |
💡
Write mobile-first with
min-width. Desktop-first max-width queries stack awkwardly and tend to produce more override code.Fluid values replace many breakpoints
:root {
font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
}
.wrap { width: min(1200px, 100% - 2rem); margin-inline: auto; }clamp(min, preferred, max)scales between bounds — perfect for type and spacing.min()/max()cap a value without media queries.vw/vhfollow the viewport; usedvhon mobile to account for collapsing browser UI.
Container queries
Media queries look at the viewport; container queries look at the parent, which is what a reusable component actually cares about.
.card-wrap { container-type: inline-size; }
@container (min-width: 420px) {
.card { display: flex; gap: 16px; }
}FAQ
Which breakpoints should I use?
There is no universal set. Add one exactly where your current layout starts to look wrong, and let content decide — not a table of device widths.
Do I still need a mobile subdomain?
No. Responsive is the standard recommendation; separate mobile sites duplicate maintenance and split signals.
Related
Last refreshed 2026-09-17.