"Media queries aren't just for responsive widths anymore. They're how CSS asks 'what kind of world am I rendering into?'"
Mobile-First: Start Small, Grow Up
Modern responsive CSS is mobile-first: the base styles target small viewports, and media queries with min-width add complexity at larger sizes. This is a discipline: mobile constraints force you to prioritize what matters; adding to a working small layout is easier than removing from a busy desktop layout.
The pattern: write the simple layout first (no media queries), then progressively enhance.
The Modern Range Syntax
The old @media (min-width: 768px) still works, but the new range syntax reads more naturally:
@media (width >= 768px)— at least 768px wide.@media (width <= 480px)— at most 480px wide.@media (480px <= width <= 1024px)— between (inclusive).
Baseline 2023. The range syntax is the modern default.
Width Isn't The Only Feature
Media queries can match many properties:
(orientation: portrait)/(orientation: landscape)— viewport aspect ratio.(prefers-color-scheme: dark)— the user's OS or browser dark mode setting.(prefers-reduced-motion: reduce)— the user prefers no animations (accessibility / vestibular disorder).(prefers-contrast: more)— high-contrast accessibility preference.(hover: hover)— the user has a pointing device that hovers (mouse, trackpad). Phones/tablets don't.(pointer: fine)/(pointer: coarse)— fine = mouse; coarse = touch.(any-pointer: fine)— at least one input is fine.(forced-colors: active)— Windows High Contrast Mode is on.(min-resolution: 2dppx)— Retina / high-DPI display.print/screen/speech— media type.
Respect prefers-reduced-motion
Some users get motion sickness from animations. Modern CSS makes it a one-liner to respect this:
Dark Mode With prefers-color-scheme
Pair with CSS custom properties for elegant theming:
The Hover Trap
Beware of :hover styles on touch devices: the browser may stick the hover state after a tap, leaving the element looking permanently "hovered". @media (hover: hover) guards your hover styles so they only apply on devices that genuinely hover:
Breakpoint Strategy
Don't pick breakpoints based on "common device sizes" — that's a 2014 strategy that aged badly (the device ecosystem is too fragmented now). Pick breakpoints based on where your content needs to change:
- Build the layout at a narrow viewport.
- Expand the browser slowly. When the layout looks bad (too wide a line, awkward gap, content too cramped), THAT'S a breakpoint.
- Add a media query to adjust at that exact width.
Content-driven breakpoints age better than device-driven ones.
Print Stylesheets
The web's oldest media query, still useful. @media print { ... } styles for printing. Common patterns: hide nav and footers, expand main to full width, force black-on-white text, show URLs after links (a::after { content: " (" attr(href) ")"; }).
prefers-color-scheme, prefers-reduced-motion, prefers-contrast, forced-colors aren't optional features — they're how you make a site that actually works for the humans behind the screen.