Skip to main content
Use container queries (@container) for component-level responsiveness and adapt the interface for different contexts—don’t just shrink it.

Mobile-First: Write It Right

Start with base styles for mobile, use min-width queries to layer complexity. Desktop-first (max-width) means mobile loads unnecessary styles first.

Breakpoints: Content-Driven

Don’t chase device sizes—let content tell you where to break. Start narrow, stretch until design breaks, add breakpoint there. Three breakpoints usually suffice: 640, 768, 1024px Use clamp() for fluid values without breakpoints:

Detect Input Method, Not Just Screen Size

Screen size doesn’t tell you input method. A laptop with touchscreen, a tablet with keyboard—use pointer and hover queries.
Critical: Don’t rely on hover for functionality. Touch users can’t hover.

Safe Areas: Handle the Notch

Modern phones have notches, rounded corners, and home indicators. Use env():
Enable viewport-fit in your meta tag:

Responsive Images: Get It Right

srcset with Width Descriptors

How it works:
  • srcset lists available images with their actual widths (w descriptors)
  • sizes tells the browser how wide the image will display
  • Browser picks the best file based on viewport width AND device pixel ratio

Picture Element for Art Direction

When you need different crops/compositions (not just resolutions):

Layout Adaptation Patterns

Three stages:
  • Mobile: Hamburger + drawer
  • Tablet: Horizontal compact
  • Desktop: Full with labels

Tables

Transform to cards on mobile using display: block and data-label attributes:

Progressive Disclosure

Use <details>/<summary> for content that can collapse on mobile:

Testing: Don’t Trust DevTools Alone

DevTools device emulation is useful for layout but misses:
  • Actual touch interactions
  • Real CPU/memory constraints
  • Network latency patterns
  • Font rendering differences
  • Browser chrome/keyboard appearances
Test on at least: One real iPhone, one real Android, a tablet if relevant. Cheap Android phones reveal performance issues you’ll never see on simulators.

Guidelines

DO

  • Use container queries (@container) for component-level responsiveness
  • Adapt the interface for different contexts—don’t just shrink it
  • Start mobile-first and layer complexity
  • Test on real devices, not just emulators
  • Use pointer and hover queries to detect input methods
  • Handle safe areas on notched devices

DON’T

  • Hide critical functionality on mobile—adapt the interface, don’t amputate it
  • Use desktop-first design
  • Do device detection instead of feature detection
  • Create separate mobile/desktop codebases
  • Ignore tablet and landscape orientations
  • Assume all mobile devices are powerful