1<meta name="viewport"2 content="width=device-width">3<div class="page">4 <main>…</main>5 <aside>…</aside>6</div>laid out 980 px widemainaside1024 px widemainaside1.page {2 display: grid;3 gap: 16px;4}5@media (min-width: 700px) {6 .page {7 grid-template-columns:8 2fr 1fr;9 }10}036070010241280width (px)≥ 700: yesnoyesdevice-widthgridgrid360px1024px2fr1fr
Left: the two files, index.html and style.cssRight: a phone and a laptop window showing the page, drawn to scaleFront: the min-width test, a ruler from 0 to 1280 px and a yes/no lampLeft: index.html (the viewport meta tag and the page) and style.css (a one-column grid, then a media query). Right: a phone and a laptop window showing the page, and the min-width test with its lamp. The meta tag makes the phone lay the page out at its own 360px. Each screen's width is tested against 700px: the phone keeps one column, the laptop splits into 2fr and 1fr columns. Dragging the laptop window below 700px turns the answer to no and the layout stacks again; at exactly 700px it is yes. A real browser checks the media query and applies every rule at once, while it works out the style of each element. The figure goes one step at a time so you can see each part.

One page, many screens

  1. Responsive design means one page whose layout adapts to the screen showing it. The same HTML opens on a phone 360 CSS pixels wide and in a laptop window 1024 wide. Nothing adapts yet, so watch what goes wrong.

Mobile first

Media queries

Resizing

What happens

;; step 1/10 · one-page
one HTML file, two screens
  phone          360 CSS px wide
  laptop window  1024 CSS px wide
no viewport tag, no CSS yet:
  main and aside stack, no gap between them

A real browser checks the media query and applies every rule at once, while it works out the style of each element. The figure goes one step at a time so you can see each part. Here the content of each box has a fixed height (main 200px, aside 120px) so the picture stays simple; real text gets taller as its box gets narrower. In two columns, grid items stretch to the height of their row, so aside grows to 200px.