Rosa checks the Westbrook Pools site on her phone before her 6 a.m. lane swim, and the first thing she sees is its main heading. It changes size with the window, so it looks like fluid type. When she plans her week on her laptop, she zooms in on the page to read the times more comfortably, and the heading has to grow along with the rest of the text.
You’ll test how the site’s heading handles both a narrow window and zoom, set its font size with a clamp() based on two sizes, and work out its size at any width and at 200 percent zoom. Start with the heading as the site ships it.
Zoom in on the Heading
A fluid heading has to fit the window and grow when someone zooms in. Before you change anything, check how the site’s heading handles both.
If you’ve come straight here, the starting site is in the course’s download, on the course page. Open its folder in your editor, start Live Preview, and open index.html in Chrome or Edge. The heading’s rule sits in the base layer of styles.css:
h1 {
font-size: 4vw;
line-height: 1.1;
}
1vw is 1 percent of the viewport’s width, so 4vw sets the heading’s font size to 4 percent of the page area’s width. Narrow the window, and the heading shrinks with it. On Rosa’s phone, 390 pixels wide, it ends up no bigger than the paragraph text below it, 15.6 pixels against 16:

That’s the first problem to fix. To test zoom, you need the heading’s size in numbers. Dock DevTools at the bottom of the window, where it doesn’t narrow the page. Then right-click the heading, choose Inspect, and find font-size in the Computed pane. In a window 1280 pixels wide, it reads 51.2px. If yours differs, multiply it by 25 for your viewport’s width.
Predict first: in that 1280-pixel window, you press Ctrl++, or Cmd++ on macOS, until the zoom level reaches 200 percent. What does the Computed pane show for the heading now, and how big does the heading look on screen?
Here, a size “on screen” is measured in CSS pixels at 100 percent zoom, whatever your display’s pixel density.
The pane shows 25.6px, half the earlier value, yet the heading looks the same size as at 100 percent. The paragraph text is twice as big.
Page zoom draws every CSS pixel bigger, twice as big at 200 percent as at 100 percent. So the same window holds only 640 CSS pixels across, and 4vw of that is 25.6 CSS pixels. Drawn at twice the size, that’s 51.2 pixels on screen, the same as before. The vw value shrinks by exactly as much as zoom enlarges it, so the two cancel out.
The paragraph is sized in rem units, which are based on the root element’s font size. The site leaves that font size at the browser’s default of 16 CSS pixels at any zoom level, as this lesson’s arithmetic assumes. At 200 percent, 1rem is drawn at 32 pixels on screen.
Pinch-zooming on a phone is different: it magnifies the whole page without changing the viewport, so it enlarges the vw heading too. Only page zoom, the kind you tried above, leaves it the same size.
Press Ctrl+0, or Cmd+0 on macOS, to go back to 100 percent. The 4vw rule was a detour, a reasonable one that looks fluid until you zoom.
A heading that zoom can’t enlarge fails the Web Content Accessibility Guidelines’ success criterion 1.4.4 Resize Text at Level AA, which requires text to be resizable up to 200 percent without loss of content or functionality. People with low vision zoom in for exactly this reason, and vw alone takes that away.
Work Out a clamp() From Two Sizes
The heading needs a part that zoom enlarges, and that’s what rem gives you. You’ve met clamp() in Responsive Design and Modern CSS: clamp(MIN, PREFERRED, MAX) uses the preferred value, but never less than the minimum or more than the maximum.
Before you rely on a feature, check its support: MDN’s page shows a Baseline badge near the top, and for clamp() it reads Baseline Widely available, meaning the feature has been available in every major browser since July 2020. Newly available means the latest browsers have it, so check your users’ browsers. Limited availability means some don’t, so plan a fallback. The pools site can use clamp() with no fallback.
The new step is the preferred value: a rem part plus a vw part, worked out from two sizes you choose.
The preferred value works like a straight line, y = b + m * x. The viewport’s width is x, the vw part is the slope m, and the rem part is the intercept b, the size the line would give a viewport zero pixels wide. The comparison holds between your two sizes. Outside them, clamp() flattens the line at its minimum and maximum.
For Rosa’s heading, pick a size at each end of the range you care about. For a viewport 320 pixels wide, use 2rem, or 32 pixels, which is twice the body text size. At 1280 pixels, use 3.5rem, or 56 pixels. Then work out the line in three steps:
- For the slope, note that the heading grows 56 − 32 = 24 pixels while the viewport grows 1280 − 320 = 960 pixels. That’s 24 ÷ 960 = 0.025 pixels per pixel of width. Since
1vwadds 0.01 pixels per pixel, the slope is2.5vw. - For the intercept, start at 320 pixels, where
2.5vwis 8 pixels. The other 32 − 8 = 24 pixels have to come fromrem, and 24 pixels is1.5rem. - For the bounds, use your two sizes,
2remand3.5rem, which keep the heading from shrinking or growing past them.
Replace the heading’s font-size in the base layer with the result:
h1 {
font-size: clamp(2rem, 1.5rem + 2.5vw, 3.5rem);
line-height: 1.1;
}
Save, and check a width in between. Turn on the device toolbar with Ctrl+Shift+M, or Cmd+Shift+M on macOS, and type 800 as the width. The line predicts 24 + 20 = 44 pixels, and the Computed pane shows 44px. Then set the width to 390 to match Rosa’s phone, and the heading stands out again:

At 390 pixels, the preferred value is 24 + 9.75 = 33.75 pixels, a little above the minimum. If your arithmetic came out differently, the button below opens a RealJS mentor chat with an editable question already filled in:
Zoom in Again
Fitting the window was half the job, so repeat the zoom test the 4vw heading failed. Turn off the device toolbar and go back to a window 1280 pixels wide. Then zoom to 200 percent. This time, the heading grows.
At 100 percent, the heading is at its maximum, 56 pixels. At 200 percent, the viewport is 640 CSS pixels wide, so the Computed pane shows 24 + 16 = 40px, drawn at 80 pixels on screen. Split the size in two to see why. The rem part, 24 CSS pixels, is drawn twice as big, at 48 pixels. The vw part halves in CSS pixels, so it stays 32 pixels on screen, as the 4vw heading did. Together, that’s 80.
The clamp() heading grows more than the 4vw heading, but it doesn’t reach twice its own size at 100 percent. Only the rem part zooms, so the bigger its share of the size, the closer zoom gets to doubling it.
To see both parts at work, drag the window width and the zoom level below, then change the rem and vw parts of the clamp() and compare each heading’s size on screen with its size at 100 percent:
Whatever the width, the 4vw heading’s size on screen stayed the same at every zoom level. The clamp() heading grew whenever a rem value was in play, either its rem part or one of its rem bounds, and the bigger that value, the more it grew.
Keep zooming, and the heading keeps growing: at 400 percent, the viewport is 320 CSS pixels wide, the heading is at its 2rem minimum, and it’s drawn at 128 pixels, more than twice its size at 100 percent. The next lesson examines the rem share of every size on the site, so that’s all you need about it for now.
Growth is only half of 1.4.4. The other half is that nothing gets clipped, overlaps, or stops working. As you step up to 400 percent, check that the heading wraps and every link still works.
The rem part also follows the default font size people can set in their browser’s settings. A vw value ignores that setting, as it ignores page zoom.
To make the model stick, ask the mentor for a worked calculation with one mistake hidden in it, then find the mistake and explain it:
Check Your Understanding
Try these before you open the answers:
- The pool cards’ names should be
1.25remon a viewport 320 pixels wide and2remat 1280. Whatclamp()gives you that? - Rosa’s friend Tomasz works out her heading,
clamp(2rem, 1.5rem + 2.5vw, 3.5rem), in a window 1000 pixels wide at 200 percent zoom: “The viewport is 500 CSS pixels wide, so it’s 24 + 12.5 = 36.5 pixels, and that’s how big Rosa sees it.” Which step is right, and what did he miss?
clamp(1.25rem, 1rem + 1.25vw, 2rem). The size grows 32 − 20 = 12 pixels over 960 pixels of width, which is 0.0125 per pixel, or1.25vw. At 320 pixels, that’s 4 pixels, so the other 16 pixels,1rem, are the intercept.- His arithmetic is right: the Computed pane shows
36.5px. But that’s in CSS pixels, and at 200 percent each CSS pixel is drawn twice as big, so Rosa sees the heading at 73 pixels on screen. At 100 percent, it was 24 + 25 = 49 pixels, so zoom enlarged it.
Rosa’s main heading now fits her phone and grows when she zooms. The rest of the site’s sizes are still fixed rem values, which zoom but don’t adapt to the window. In the next lesson, Turn Fluid Sizes Into a Scale, you’ll give them the same treatment as a set of fluid tokens, or reusable named values.