What is responsive design?

Responsive design is building one website whose layout, images and typography adapt to any screen size, orientation and input method, from phones to large desktop monitors, instead of making separate mobile and desktop sites. It rests on fluid layouts, flexible media and media (or container) queries.

The core ingredients (Ethan Marcotte's original three, plus modern tools)

  1. Fluid layouts: relative units (%, fr, rem), Flexbox and Grid instead of fixed pixel widths.
  2. Flexible media: img { max-width: 100%; height: auto; }, srcset/sizes, <picture>, aspect-ratio.
  3. Media queries: adjust the layout at breakpoints.
  4. Modern additions: container queries for components, clamp() for fluid type and spacing, intrinsic grids (auto-fill + minmax), viewport units like dvh.

Essential setup

<meta name="viewport" content="width=device-width, initial-scale=1">; without it, mobile browsers render the page at about 980px wide and zoom out.

Beyond screen size

  • Input: touch targets, (hover: hover) and (pointer: coarse).
  • User preferences: dark mode, reduced motion, zoom up to 400% (WCAG 1.4.10 Reflow: no horizontal scrolling at 320 CSS px).
  • Performance on slower devices and networks.

Testing

DevTools device mode, real devices, and simply resizing the browser through every width, not only common device sizes.

Interview tip

Mention container queries and clamp(); they show you know responsive design has moved beyond only media queries.

Code example

html
1<style>
2 * { box-sizing: border-box; }
3 body { font-family: system-ui; margin: 0; }
4 .wrap { width: min(100% - 2rem, 70rem); margin-inline: auto; } /* fluid, capped */
5 h1 { font-size: clamp(1.5rem, 1rem + 3vw, 3rem); } /* fluid type */
6 .grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr)); }
7 .card { container-type: inline-size; border: 2px solid #0b1020; border-radius: 10px; overflow: hidden; }
8 .card img { width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
9 .card p { padding: .75rem; margin: 0; }
10 /* Container query: the card adapts to its own width, not the viewport */
11 @container (min-width: 20rem) { .card p { font-size: 1.1rem; } }
12</style>
13<div class="wrap">
14 <h1>One site, every screen</h1>
15 <div class="grid">
16 <article class="card"><img src="https://picsum.photos/id/1035/640/360" alt="Waterfall" width="640" height="360"><p>Fluid grid</p></article>
17 <article class="card"><img src="https://picsum.photos/id/1036/640/360" alt="Snowy mountains" width="640" height="360"><p>Flexible images</p></article>
18 <article class="card"><img src="https://picsum.photos/id/1037/640/360" alt="Forest" width="640" height="360"><p>Container queries</p></article>
19 </div>
20</div>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app