Chapter Five · Look
Responsive Design
One page for every screen: the viewport line and the mobile-first habit, media queries that answer both the screen width and the person's own settings, layouts that adapt with no breakpoints at all, and images that weigh only what each screen needs.
By the end of Chapter 4 the site has a real layout, and on a phone it does not fit: three card columns squeezed so tight that they push past the edge of the screen. The answer is not a second site for phones. It is one set of files whose layout adapts to whatever screen it lands on, and whose styles also listen to what the visitor has asked for, such as a dark screen or less motion. That is responsive design, and this chapter builds it into the site.
Four topics. One page, every screen: the viewport line that stops phones shrinking the page, why fixed widths break, writing for the narrow screen first, and testing in device mode. Media queries and user preferences: breakpoints chosen by the content, the site's grid at two widths, a dark theme from a few tokens, and reduced motion. Fluid layouts: clamp() and its relatives, a card grid that counts its own columns, and container queries. And responsive images: the right file for each screen, newer formats with a fallback, and images that wait until they are needed.
Topics in This Chapter
min(), max() and clamp(), headings that grow without breaking zoom, a card grid with no breakpoints, and container queries.srcset and sizes, picture for newer formats, and lazy loading.