The video picks up with Rosa’s home page as the previous lesson, Make Fluid Headings That Still Zoom, left it: a main heading that fits her phone and grows when she zooms, and every other size still a fixed rem value.
In this video, you turned the site’s size tokens into a fluid scale. You put semantic tokens between the primitives and the rules that read them, gave each primitive a clamp() worked out from two sizes, and checked every step at 320 pixels, in a wide window and at 200% zoom. Here are the main points and the final tokens.
Key Points
- The size tokens live on
:rootin thebaselayer. Primitives hold values, one step on a scale each. Semantic tokens name a role, such as the header’s gap, and point at a primitive. Components read only the roles. - Add the roles first. When the body, the subheading and the components read semantic tokens that point at the same primitives, nothing on the page changes.
- Then make only the primitives fluid. Each step keeps its fixed value at 320 pixels, which becomes the minimum of its
clamp(), and is an eighth bigger at 1280 pixels, so body text goes from 16 pixels to 18. The eighth is a choice: small growth keeps most of each size inrem. Eachclamp()comes from those two sizes, as the heading’s did. - The step numbers keep their meaning. A spacing step’s number counts quarter rems, so
--space-4is1rem. A type step’s number counts steps up a 1.25 scale, so--text-3is three steps up. Both stay true at 320 pixels, where each step keeps its value. - The scale gets a new top step,
--text-4, one step above--text-3, so on a phone the heading grows from 32 pixels to 39.--space-8and--space-16join the spacing steps, for later pages. Two new roles point at new steps:--font-size-heading, which the main heading reads, and--space-stack, for the space between stacked blocks. - Some steps have no rule yet, so the home page can’t show them. Make a scratch page,
scale.html, that linksstyles.cssand has a line of text per type step and a bar per spacing step, each reading one primitive, such as.text-1 { font-size: var(--text-1); }and.space-8 { inline-size: var(--space-8); }. It’s a check aid, not part of the site, and it lets you check every step. - Check the narrow end with the device toolbar at 320 pixels: every step is at its minimum (body text and the header’s gap 16 pixels, the panel’s padding 24, the heading 39), and there’s no sideways scroll. Then turn off the device toolbar and widen the real window to 1280 pixels: body text and the gap reach 18 pixels, and the padding 27.
- Check at 200% zoom in that wide window. The viewport drops to 640 CSS pixels, and the Computed pane shows body text at 16.7 pixels. Drawn twice as big, that’s 33.3 on screen, against 18 before: 1.85 times. Close to twice is what you want, and every other step comes out 1.85 times too.
- Watch out:
rembounds alone don’t make a step zoom. Between its bounds, the preferred value decides, and zoom shrinks itsvwpart. Kept at 56 pixels (3.5rem) in a wide window, the top step’s preferred value had the mostvwof any step, and the heading came out only 1.6 times as big. - The fix: bring its wide size down to an eighth bigger,
2.746rem. That gives it a gentler slope and mostlyrem, and it comes out 1.85 times as big too. The cost: the heading now tops out at 44 pixels in a wide window instead of 56. - The more a step grows with the window, the less it grows with zoom. So keep the growth small, and confirm it at 200%.
The Final Code
The :root rule in the base layer of styles.css, with the color tokens left as they were:
:root {
/* Primitives */
--text-0: clamp(1rem, 0.958rem + 0.209vw, 1.125rem);
--text-1: clamp(1.25rem, 1.198rem + 0.26vw, 1.406rem);
--text-2: clamp(1.5625rem, 1.497rem + 0.327vw, 1.758rem);
--text-3: clamp(1.953rem, 1.871rem + 0.408vw, 2.197rem);
--text-4: clamp(2.441rem, 2.339rem + 0.509vw, 2.746rem);
--space-2: clamp(0.5rem, 0.479rem + 0.104vw, 0.562rem);
--space-4: clamp(1rem, 0.958rem + 0.209vw, 1.125rem);
--space-6: clamp(1.5rem, 1.437rem + 0.314vw, 1.688rem);
--space-8: clamp(2rem, 1.916rem + 0.418vw, 2.25rem);
--space-16: clamp(4rem, 3.833rem + 0.834vw, 4.5rem);
/* Semantic tokens */
--font-size-body: var(--text-0);
--font-size-heading: var(--text-4);
--font-size-subheading: var(--text-2);
--space-gap: var(--space-4);
--space-inset: var(--space-6);
--space-control-block: var(--space-2);
--space-control-inline: var(--space-4);
--space-stack: var(--space-8);
}
The rules that read them:
body {
font-size: var(--font-size-body);
}
h1 {
font-size: var(--font-size-heading);
}
h2 {
font-size: var(--font-size-subheading);
}
.site-header {
gap: var(--space-gap);
padding-inline: var(--space-inset);
}
.today-link {
padding-block: var(--space-control-block);
padding-inline: var(--space-control-inline);
}
.today-panel {
padding: var(--space-inset);
}
Each rule keeps its other declarations.
Next, in Exercise: Build the Lido Page’s Fluid Scale, you’ll give Riverside Lido’s page a scale of its own. It’s this course’s first coding exercise, and its Contents tab explains how exercises work.