Color scheme

Web Fonts

Every font you see in a browser either came bundled with the operating system or traveled across a network as a separate file. System fonts are instant: they are already on disk. Web fonts are not. The browser has to discover that a font is needed, request the file, download it, parse it, and then decide what to show the visitor while all of that is happening. That gap between "page starts loading" and "font is ready" is where most web font problems live. This reading assignment covers how to declare web fonts, how to control the rendering gap, how variable fonts change the economics of font loading, and how to make smart pairing and budget decisions.

Declaring Fonts with @font-face

The @font-face rule tells the browser where to find a font file and what CSS properties that file satisfies. You write one block per combination of family, weight, and style. A family with four weights (regular, medium, semibold, bold) and two styles (normal, italic) requires eight @font-face blocks, which we will cover shortly when discussing variable fonts.


        @font-face {
            font-family: 'Inter';
            src:
                url('/fonts/inter-regular.woff2') format('woff2'),
                url('/fonts/inter-regular.woff')  format('woff');
            font-weight: 400;
            font-style: normal;
            font-display: swap;
            unicode-range: U+0000-00FF, U+0131, U+0152-0153;
        }
    

The src Stack

The src descriptor accepts a comma-separated list of sources. The browser tries each in order and uses the first one it can load. woff2 should always come first: it has the best compression (typically 30% smaller than woff) and is supported by every browser that matters today. The woff fallback covers older environments if you need them. You rarely need ttf or eot in a modern project.

You may also see local('Inter') listed before the URL sources. This checks whether the font is already installed on the visitor's system and skips the download if so. It sounds appealing but has two problems: the string must match the font's internal PostScript name exactly (which varies by vendor and version), and it can cause subtle rendering differences when the locally installed version is older than your intended design. Most teams omit local() and serve the file consistently.

Weight and Style Descriptors

The font-weight and font-style descriptors on a @font-face block do not set the weight of the text. They describe which CSS weight value this particular file satisfies. When an element is styled with font-weight: 700, the browser looks for a @font-face block whose font-weight descriptor covers 700 and loads that file. If no exact match exists, the browser synthesizes bold by thickening the glyphs algorithmically, which almost always looks worse than a real bold cut.


        /* Each block maps to a specific weight */
        @font-face {
            font-family: 'Inter';
            src: url('/fonts/inter-400.woff2') format('woff2');
            font-weight: 400;
            font-style: normal;
            font-display: swap;
        }

        @font-face {
            font-family: 'Inter';
            src: url('/fonts/inter-700.woff2') format('woff2');
            font-weight: 700;
            font-style: normal;
            font-display: swap;
        }
    

Unicode Range

The unicode-range descriptor tells the browser which characters this file covers. If none of those characters appear on the current page, the browser skips the download entirely. This is how Google Fonts serves Latin, Greek, Cyrillic, and Vietnamese subsets as separate files. A page with only Latin text never requests the Cyrillic file. For self-hosted fonts you can generate subset files with tools like Google Fonts Knowledge or pyftsubset and declare each subset range separately.

Self-Hosted vs. Google Fonts

Google Fonts generates the @font-face blocks for you and serves files from its CDN. That is convenient, but it adds a cross-origin request and gives you less control over caching and subsetting. Self-hosting (downloading the files and serving them from your own origin) removes the third-party dependency and lets you set long cache headers. The course uses Google Fonts via a <link> in the HTML head; when you build your own project you can choose either approach, but self-hosting is generally preferred for production sites.

Controlling the Rendering Gap with font-display

Between when the browser discovers it needs a font and when the file finishes downloading, every text node that uses that font is in an uncertain state. The browser has to make a choice: show nothing, show a fallback, or show the fallback and swap it out later. The font-display descriptor controls that choice.

The browser's font loading timeline has three named periods. The block period is an initial window where text is invisible. The browser reserves space but renders nothing, waiting for the font. The swap period follows: the font is still loading but the browser now renders text in a fallback font. The failure period begins when the browser gives up on loading the font and continues with the fallback permanently. Each font-display value sets different durations for these periods.

The Five Values

  • block: A short block period (typically 3 seconds), then an infinite swap period. Text is invisible during the block period. Use this only for icon fonts where fallback characters would be meaningless.
  • swap: An extremely short block period (around 100ms), then an infinite swap period. Text shows immediately in a fallback, then jumps to the web font when it arrives. This causes layout shift but ensures text is always readable. The most commonly used value.
  • fallback: A very short block period, then a short swap period (around 3 seconds), then failure. If the font does not arrive within the swap window, the fallback stays permanently for that page load. A good balance for body text.
  • optional: An extremely short block period and no swap period. The browser uses the font only if it is already cached or arrives near-instantly. Otherwise the fallback is used for the entire page load with no swap. Best for non-essential decorative fonts.
  • auto: Browser default, usually equivalent to block. Avoid it and be explicit instead.
The quick brown fox
jumps over the lazy dog, rendered in your web font
Block
invisible text
Swap
fallback font
Loaded
web font paints

In practice, swap is the right default for body text and headings where readability during load matters most. Use optional for decorative or accent fonts that are not critical to reading the content. Avoid block except for icon fonts.

Variable Fonts

A traditional font family ships one file per weight and style: regular, italic, bold, bold italic, and so on. A family with six weights and italic variants means twelve files, twelve network requests, and twelve things that can slow your page down or render incorrectly if one fails to load.

Variable fonts solve this with a single file that encodes a continuous range of values along one or more design axes. Instead of separate files for weight 400 and 700, a variable font contains the full range from 100 to 900 in one download. You access any value along the axis with font-weight as usual, or with the lower-level font-variation-settings property for axes that do not have a named CSS property.


        @font-face {
            font-family: 'Inter';
            src: url('/fonts/inter-variable.woff2') format('woff2-variations');
            font-weight: 100 900;   /* declares the supported range */
            font-style: normal;
            font-display: swap;
        }

        /* Then use any weight value in that range */
        h1 { font-weight: 750; }
        p  { font-weight: 380; }
    

The font-weight descriptor on a variable @font-face takes two values (the minimum and maximum of the supported range) rather than a single number. The browser maps any requested weight between those values to the appropriate position in the font's weight axis.

Registered vs. Custom Axes

The OpenType spec defines several registered axes that have named CSS properties: wght (weight), wdth (width), ital (italic), slnt (slant), and opsz (optical size). Use the CSS property when one exists: font-weight, font-stretch, and so on. Font designers can also define custom axes using four-letter uppercase tags. These have no CSS property shorthand and must be set via font-variation-settings:


        /* Registered axis: use the CSS property */
        h1 { font-weight: 700; }

        /* Custom axis: must use font-variation-settings */
        .display-text {
            font-variation-settings: 'GRAD' 150, 'YOPQ' 90;
        }
    

One important caveat: font-variation-settings is not inherited the way font-weight is. If you set it on a parent, child elements do not automatically receive it unless they also declare it. For registered axes, always prefer the named CSS property over font-variation-settings so inheritance works as expected.

Is the Font Variable?

Not all fonts on Google Fonts are variable. Look for the "Variable" badge on the font's detail page, or check the downloaded file name. Variable fonts typically include "VariableFont" or "VF" in the filename. In DevTools, loading a variable font shows one network request for one file where a static family would show multiple.

Pairing and Limiting Axes

Most well-designed interfaces use two typefaces: one for body text and one for headings or UI chrome. Adding a third introduces visual noise that requires significant typographic skill to resolve. The course uses Inter for body and UI text and Fira Code for code samples. These two faces have a clear functional distinction between them.

Contrast Principles

A pairing works when the two faces are similar enough to feel like they belong in the same design but different enough to signal a change in content type. The most reliable contrast strategies are:

  • Sans + mono: The most common pairing in interfaces built for developers. The monospace face reads as technical or code related; the sans reads as prose or interface text. This is exactly what the course uses.
  • Serif + sans: Classic editorial pairing. The serif brings warmth and authority to display text; the sans provides clean readability for body text. Works well for content heavy or editorial sites.
  • Same family, different weights: If a family has enough weight range, pairing a light or regular weight for body with a heavy weight for headings creates contrast without needing two families at all. Reduces requests and guarantees visual harmony.

Avoid pairing two serif faces or two sans-serif faces of similar style and weight. The visual difference is too subtle to feel intentional and reads as a mistake rather than a design decision.

Limiting Design Axes

Variable fonts make it tempting to use many values across a wide axis range. A heading at weight 800, a subheading at 650, a label at 520, body at 400: each choice feels purposeful in isolation, but the cumulative result is a hierarchy that requires effort to decode. Limit yourself to three or four weight stops across an entire design, and use them consistently by role. The same discipline applies to width, optical size, and any custom axes a font exposes.

Weight Budgets and Font Loading

Every font file you load is a network request that delays rendering. The practical budget for web fonts on a typical content page is two to three files totaling under 150kb. Modern woff2 variable fonts for a well-optimized family typically land between 50kb and 100kb, which leaves room for one additional font before the budget is strained.

Font requests have a particular characteristic in the network waterfall: they are discovered late. The browser must download and parse HTML, then download and parse CSS, and only then find the @font-face declarations that tell it fonts are needed. By that point, other resources are already downloading and competing for bandwidth. You can move font requests earlier with a <link rel="preload"> tag in your HTML head:


        <link
            rel="preload"
            href="/fonts/inter-variable.woff2"
            as="font"
            type="font/woff2"
            crossorigin
        >
    

The crossorigin attribute is required even for same-origin font files because of how the font loading specification works. Omitting it causes the browser to make two requests for the same file.

Viewing the Real Waterfall in DevTools

Open DevTools, go to the Network tab, and filter by Font. Reload the page with the cache disabled (the reload button while DevTools is open, or Shift+Reload). Each font file appears as a bar showing when the request started, how long it spent waiting, and how long the download took. The gap between page start and when the first font bar begins is the discovery delay: the time spent parsing HTML and CSS before the browser knew fonts were needed.

The demo below fetches the actual font files the course uses and measures the real download time in your browser right now. A small visual baseline is added to each bar so differences in waiting time versus download time are always easy to see. Press Fetch Again to run a fresh load.

Font File
Timeline (relative to page start)
Total
Fetching fonts…

Putting It Together

The course token file declares two font family tokens: --font-family-sans (Inter) and --font-family-mono (Fira Code). Both are loaded via Google Fonts, which generates the @font-face blocks automatically. When you build your own project you will write those blocks yourself, choosing your own families, subsetting aggressively, declaring the right font-display value for each role, and considering a variable font if your design calls for more than two or three weights.

The decisions covered here (block vs. swap, one variable file vs. many static files, two typefaces vs. three) are not aesthetic preferences. Each one has a measurable impact on load time, layout stability, and readability. Making them deliberately, with an understanding of the tradeoffs, is what separates a production-ready typography system from one that just happens to look right on a fast laptop with a warm cache.