How to build a responsive website that works on every screen size
Responsive design means a single site adapts to phones, tablets, laptops and large monitors. The modern toolkit makes this much easier than it used to be.
Core principles
- Start with the viewport meta tag so mobile browsers do not render a zoomed-out desktop page.
- Design mobile-first. Write base styles for small screens, then add
min-widthmedia queries for larger ones. - Use flexible units. Percentages,
rem,frand viewport units adapt better than fixed pixel widths. - Let layouts flow. Flexbox wrapping and Grid with
auto-fill/minmax()often remove the need for many breakpoints. - Make images responsive.
max-width: 100%,srcsetandsizesserve the right image for each screen. - Use fluid typography.
clamp()lets font sizes scale smoothly between a minimum and maximum.
Newer tools worth learning
- Container queries let components respond to the size of their container rather than the whole viewport, which is ideal for reusable components
- Logical properties (
margin-inline,padding-block) handle different writing directions
Test properly Device emulation in dev tools is helpful, but testing on real phones catches touch target sizes, font rendering and performance issues.
What breakpoints do you actually use? Have container queries changed how you build components?
Comments · 3
Please also test at awkward in-between widths, not just the usual phone, tablet and desktop. Most layout bugs I see live at about 800px or on a phone in landscape.
Responsive design is table stakes now, but performance on slow mobile connections is where conversion gets decided. A layout that adapts but loads slowly still loses users.
Do you prefer container queries over media queries for components these days? I'm curious whether people actually use them in production or are still waiting for browser support to feel safe.