Chapter 05 of 09Part 2 · Layout

Responsive web design, from phone to wide screen

One page that works on every screen: the viewport tag, mobile first media queries, fluid type and images that fit.

10 minBy Zuzo StudioUpdated

10 min

In this chapter you will

  • set up the viewport so phones show your page at its real width
  • write mobile first media queries with breakpoints taken from your content
  • size type, spacing and images so they adapt smoothly to any screen

Before you startThis builds on Flexbox vs grid: laying out a page.

Check your understanding

3 questions

Q1Your media query for screens under 40em works in a desktop browser window but never on a real phone. What is the most likely cause?

Show the answer

The page is missing the viewport meta tag Without it, many phones lay the page out at a wide virtual width, often around 980 pixels, so a query for narrow screens is never true.

Q2Why is font-size: clamp(2rem, 1.2rem + 3vw, 4rem) better than font-size: 5vw?

Show the answer

It has a minimum and a maximum, and the rem part lets the text grow when someone zooms 5vw can become tiny on a phone and huge on a wide monitor, and text sized only in vw does not get bigger when the page is zoomed.

Q3What is the best way to choose breakpoints?

Show the answer

Widen the browser slowly and add a breakpoint where the layout starts to look wrong Breakpoints taken from your content work for every device, including ones that do not exist yet.

Key takeaways

  1. Without the viewport meta tag, phones lay the page out as if they were a desktop screen and your media queries never fire.
  2. Write the small screen styles first, then add min-width media queries where the content starts to look wrong, not at device sizes.
  3. clamp() gives type and spacing a minimum, a fluid middle and a maximum; keep a rem part so text still grows when people zoom.
  4. max-width: 100% stops images breaking the layout, and srcset with sizes stops phones downloading desktop sized files.
Up next · Chapter 06 · 8 min Progressive enhancement: what JavaScript is for Make the page work with HTML first, then let JavaScript add extras. What scripts should and should not be trusted with.

02FAQ

Questions on this chapter

Something else on your mind? Email the studio and a designer, not a salesperson, replies within a day.

What is responsive web design?

It is the practice of building one page that adapts to any screen, from a small phone to a wide monitor, using flexible layouts, fluid sizes, flexible images and media queries. The term was coined by Ethan Marcotte in 2010.

What are the most common breakpoints for responsive design?

There is no standard set, and copying device widths goes out of date quickly. Start with the small screen layout, widen the browser slowly, and add a breakpoint, ideally in em, wherever your content starts to look wrong.