Responsive Design
Also Known As
TL;DR
Explanation
Responsive design, coined by Ethan Marcotte in 2010, has three technical components: a fluid grid (using percentages or fr units instead of fixed pixels), flexible images (max-width: 100% prevents images from overflowing their containers), and media queries (@media rules that apply different CSS at different viewport widths). The viewport meta tag (<meta name='viewport' content='width=device-width, initial-scale=1'>) is required to prevent mobile browsers from rendering at desktop width and scaling down. Modern CSS has largely superseded custom media query breakpoints for layout — CSS Grid and Flexbox with min-content/max-content sizing create intrinsically responsive layouts without breakpoints. The mobile-first approach writes base styles for mobile and adds complexity for larger screens, which generally produces simpler CSS.
Common Misconception
Why It Matters
Common Mistakes
- Missing the viewport meta tag — without it, mobile browsers render at 980px wide and scale down, making text tiny.
- Using fixed pixel widths for layout containers — use max-width with 100% width, or CSS Grid/Flexbox.
- Setting touch targets smaller than 44×44px — iOS and Android guidelines both specify minimum 44px tap target size for accessibility.
- Testing only in browser DevTools device emulation — real devices behave differently, especially for touch events and font rendering.
Code Examples
/* Fixed desktop layout — breaks on mobile */
.container {
width: 960px; /* overflows on phones */
margin: 0 auto;
}
.sidebar { float: left; width: 240px; }
.main { float: left; width: 720px; }
/* Responsive — mobile-first */
.container {
width: 100%;
max-width: 960px;
margin: 0 auto;
padding: 0 1rem;
}
/* Single column on mobile by default */
.layout { display: grid; gap: 1.5rem; }
/* Two-column on wider screens */
@media (min-width: 640px) {
.layout { grid-template-columns: 240px 1fr; }
}