Color scheme

Type Scale and Fluid Type

Most design systems do not pick font sizes one at a time. They build a scale: a small set of sizes that relate to each other mathematically, then assign those sizes to roles across the interface. This reading assignment covers how scales are constructed, how to make them fluid across viewport widths using clamp(), and how the course token file puts both ideas into practice.

Why a Scale Instead of Arbitrary Sizes

Without a system, font sizes accumulate over time. One developer sets a heading to 28px, another uses 26px for something similar, a third reaches for 30px because it "looked right." The result is a pile of one-off values with no relationship to each other, which makes changes expensive: adjusting the visual hierarchy means hunting down every hard-coded number.

A type scale solves this by deriving every size from a single base value and a ratio. Multiply the base by the ratio to get the next step up; divide to get the next step down. Every size in the system is mathematically related, so the whole scale shifts when the base changes, and the proportions hold automatically. This is called a modular scale.

Picking a Ratio

Common ratios have names borrowed from music theory, where the same ratios describe harmonic intervals. The most useful ones for the web are:

  • Minor Third (1.2): Subtle steps, good for dense UI or small screens where you need multiple sizes that do not diverge dramatically
  • Major Third (1.25): A versatile middle ground, used by many large design systems including Google's Material Design baseline
  • Perfect Fourth (1.333): Noticeable contrast between steps, well-suited to editorial layouts where display sizes should feel distinct from body text
  • Golden Ratio (1.618): Dramatic jumps; works for minimal pages with few type sizes but produces unwieldy values at larger steps

The ratio is a starting point, not a law. Real systems often round computed values to cleaner numbers and occasionally adjust a step that lands awkwardly. The goal is a set of sizes that feels harmonious, not pixel-perfect adherence to a formula.

The Course Scale

The course token file (tokens/variables.css) defines eight named steps. Because the stylesheet sets font-size: 62.5% on html, 1rem equals 10px at the browser's default size, which makes the rem values easy to read as pixel equivalents:


        --font-size-xs:  1.2rem;   /* 12px */
        --font-size-sm:  1.5rem;   /* 15px */
        --font-size-md:  1.8rem;   /* 18px */
        --font-size-lg:  2.1rem;   /* 21px */
        --font-size-xl:  2.4rem;   /* 24px */
        --font-size-2xl: 2.7rem;   /* 27px */
        --font-size-3xl: 3.0rem;   /* 30px */
        --font-size-4xl: 3.6rem;   /* 36px */
    

Each step in the lower range is roughly 1.2× the previous (minor third). The jump from 3xl to 4xl widens to 1.2× as well, but the even spacing across the middle keeps the scale readable without dramatic leaps. Each size also has a paired line-height token tuned by role: body sizes use a ratio around 1.5 for comfortable prose reading, while larger display sizes use tighter values so multi-line headings do not balloon.

From Fixed to Fluid with clamp()

Fixed sizes work, but they make you choose: optimize for mobile and the desktop headings feel small, or optimize for desktop and the mobile headings crowd the screen. Media queries help, but you end up maintaining two or three discrete values for each step rather than one continuous range.

The clamp() function gives you a single declaration that covers the full range. It takes three arguments: a minimum, a preferred value, and a maximum. The browser uses the preferred value as long as it falls between the other two, and clamps to the boundary when it does not.


        font-size: clamp(minimum, preferred, maximum);
    

The minimum and maximum are fixed sizes. The preferred value is where the fluid behavior lives: a length tied to the viewport width (vw) so it grows and shrinks as the window does. The result is a font size that scales smoothly between your two endpoints without a single media query.

A Simple Example

Say you want a heading that is 2.4rem on a 320px screen and 3.6rem on a 1200px screen, scaling linearly between those two points. A first attempt might look like this:


        font-size: clamp(2.4rem, 4vw, 3.6rem);
    

At 4vw, the preferred value hits 2.4rem (24px) when the viewport is 600px wide and 3.6rem (36px) at 900px. That range is narrower than intended. Picking the right vw multiplier by feel is imprecise. The next section shows the calculation that produces an exact match for any two breakpoints.

What the Viewport Slider Shows

The demo below simulates a viewport narrowing and widening. Drag the slider to see how a fixed size stays frozen while a fluid size scales continuously between its minimum and maximum. Notice the point where the fluid size hits its floor and its ceiling — the scaling stops there, and it becomes a fixed size again at the extremes.

Simulated Viewport: 760px
Heading
Page Heading fixed 2.4rem
Heading
Page Heading
Body
The quick brown fox jumps over the lazy dog. fixed 1.8rem
Body
The quick brown fox jumps over the lazy dog.
Fixed (always the same size)
Fluid with clamp()

Calculating the Right vw Value

To make the preferred value in clamp() produce exact sizes at your chosen breakpoints, you need a linear equation rather than a guessed multiplier. The goal is a line that passes through two known points: (min-viewport, min-size) and (max-viewport, max-size).

The equation for a line is y = mx + b, where x is the viewport width, y is the font size, m is the slope, and b is the y-intercept. In CSS terms, the slope becomes the vw multiplier and the intercept becomes a rem offset:


        /* slope = (max-size - min-size) / (max-vw - min-vw) */
        /* intercept = min-size - (slope × min-vw) */

        font-size: clamp(min-size, slope-vw + intercept-rem, max-size);
    

A Worked Example

Suppose you want a heading token that is 2.4rem (24px) at a 320px viewport and 3.6rem (36px) at a 1200px viewport. Work in px throughout, then convert the result to rem at the end.


        /* Step 1: slope */
        /* (36 - 24) / (1200 - 320) = 12 / 880 ≈ 0.01364 */
        /* As a vw percentage: 0.01364 × 100 = 1.364vw */

        /* Step 2: intercept (plug in the min point to solve for b) */
        /* b = 24 - (0.01364 × 320) = 24 - 4.364 ≈ 19.636px → 1.9636rem */

        font-size: clamp(2.4rem, 1.364vw + 1.9636rem, 3.6rem);
    

You can verify this by plugging the viewport widths back in. At 320px: 1.364 × 3.2 + 19.636 = 24.0px. At 1200px: 1.364 × 12 + 19.636 = 35.99px (rounding accounts for the tiny gap). The size at any viewport between those two is interpolated automatically.

Do the Math Once, Then Use a Tool

Understanding the derivation above is important so you know what the tool is doing and can sanity-check its output. Once you have that understanding, Utopia does the arithmetic for you: enter your min and max viewports, your min and max sizes for each step, and it outputs ready-to-paste clamp() declarations for an entire scale. It also visualizes how each step grows across the viewport range, which makes it easy to spot steps that scale too aggressively or not enough.

The tokens/variables.css file uses fixed steps rather than fluid ones, which is appropriate for a shared course UI. When you build your own portfolio, you will have the opportunity to define a fluid scale and map it to the same role tokens.

Mapping Roles to Steps

A numeric scale gives you sizes. Semantic role tokens give those sizes meaning. The distinction matters because the name of a token should describe its purpose, not its measurement. A token called --font-size-xl tells you where something sits on the scale; a token called --font-size-heading-sm tells you what it is for. When you later decide a small heading should be slightly larger, you change one value in one place rather than hunting down every element that happened to use xl.

The pattern is a two-layer system. The first layer is the scale itself, the named numeric steps you have already seen. The second layer maps those steps to roles:


        /* Layer 1: the scale (source of truth for sizes) */
        --font-size-sm:  1.5rem;
        --font-size-md:  1.8rem;
        --font-size-lg:  2.1rem;
        --font-size-xl:  2.4rem;
        --font-size-2xl: 2.7rem;
        --font-size-3xl: 3.0rem;

        /* Layer 2: semantic roles pointing at scale steps */
        --font-size-body:        var(--font-size-md);
        --font-size-body-sm:     var(--font-size-sm);
        --font-size-caption:     var(--font-size-xs);
        --font-size-heading-sm:  var(--font-size-xl);
        --font-size-heading-md:  var(--font-size-2xl);
        --font-size-heading-lg:  var(--font-size-3xl);
        --font-size-display:     var(--font-size-4xl);
    

Components then use role tokens, never scale steps directly. A card title uses --font-size-heading-sm; a caption uses --font-size-caption. If a design decision changes which scale step a role should use, the change is made in one place and flows everywhere that role appears.

The tokens/variables.css file defines the scale steps. You will add the role layer when building your portfolio's typography system. The two-layer approach is the same pattern the course uses for colors: seed values (scale) and semantic tokens (roles) pointing at them, as seen in tokens/colors.css.

Line Height Pairs

Every size token in the course file has a corresponding --line-height-* token at the same step name. These are tuned individually rather than derived from a formula because the right reading rhythm changes by role. Body text at --font-size-md (18px) uses --line-height-md (28px), a ratio of roughly 1.55. The display size at --font-size-4xl (36px) uses --line-height-4xl (40.5px), a much tighter 1.125. Multi-line headings at display sizes need tight leading to feel like one visual unit; multi-line body paragraphs need open leading so lines do not blur together under sustained reading.

When you define role tokens, pair each size token with its line-height counterpart so components can consume both together. A token set like --font-size-body and --line-height-body is easier to apply consistently than remembering to look up the right line-height separately each time.

Putting It Together

A complete typography token system has three pieces: a modular scale that provides consistently spaced size options, fluid declarations using clamp() that let each step adapt across viewport widths, and a semantic role layer that assigns meaning to each step so components consume tokens by purpose rather than measurement. The course file gives you the scale; the next assignment will have you apply these ideas to build the role layer and the fluid declarations for your own portfolio.

One thing worth keeping in mind as you work: the math and the tooling exist to serve readability. A scale computed from a perfect ratio that produces sizes nobody can comfortably read is not a good scale. Always test your type at real viewport widths in a real browser, and adjust the clamp boundaries if the minimum or maximum feel off for the content they hold.