Font Families and Web Fonts
How font-family fallback stacks work, what the generic families are for, and how @font-face loads your own files, and why self-hosted WOFF2 is the default.
Font Families and Web Fonts
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- `font-family` takes a list. The browser uses the first family that is installed or loaded, and falls back per character if a glyph is missing. Always end the list with a generic family such as `sans-serif`.
- Family names containing spaces or digits are quoted (`"Source Serif 4"`). Generic keywords are never quoted: `serif`, `sans-serif`, `monospace`, `system-ui`, `ui-monospace`.
- `@font-face` maps a name you choose to one or more font files. Each face declares its `font-weight` and `font-style` so the browser can pick the right file for `bold` or `italic`.
- Ship WOFF2: it is compressed, and supported by all current browsers. Listing older formats is rarely worth it now.
- Self-hosting fonts means no request to a third-party host, full control of caching and preloading, and no third-party data transfer, at the cost of managing the files yourself.
A list, not a choice
Say you write font-family: "Gill Sans". Your reader’s computer does not have it. Where do the letters come from? The browser’s default, probably a serif, which is not what you meant. So font-family is a fallback list: you name what you want first, and then what is acceptable instead.
body {
font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
}
The browser works left to right and uses the first family it can find, either installed on the device or loaded through @font-face. The matching also works glyph by glyph: if the first font lacks an emoji or a rarely used character, the browser tries the next family for that character alone.
The generic families
The last entry should be a generic family, a keyword that stands for “whatever font this device has in this style”: serif, sans-serif, monospace, cursive, fantasy. They are never quoted, and quoting one makes it a family named “serif” instead. Names with spaces or digits, such as "Times New Roman" or "Source Serif 4", should be quoted.
Newer generics point at the operating system’s own interface fonts: system-ui is the platform UI font (San Francisco on Apple devices, Segoe UI on Windows), and ui-monospace, ui-serif and ui-rounded do the same for other styles. A stack that begins with them costs no download, looks native, and loads instantly:
body {
font-family: system-ui, sans-serif;
}
code {
font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
}
Loading your own font with @font-face
To use a font that is not on the reader’s device, you tell the browser where to download it:
@font-face {
font-family: "Brand";
src: url("/fonts/brand-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Brand";
src: url("/fonts/brand-bold.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
body { font-family: "Brand", system-ui, sans-serif; }
font-family here is a name you invent; it only has to match what you use later. Each @font-face is one face: one file for one weight and style. Two rules with the same name build up one family with a regular and a bold. font-weight: 700 in the stylesheet then selects the bold face by matching the weight you declared, not by reading the file.
If you declare only a regular face and ask for bold, the browser synthesizes one by thickening the outlines, and an italic by slanting. These faux styles look worse than a designed one, so supply real faces, or use a variable font (next lesson). font-synthesis: none turns the faking off.
font-display and loading performance are covered in the next lesson. unicode-range limits a face to certain characters so that, for example, a Cyrillic file downloads only if the page actually contains Cyrillic.
Formats
Use WOFF2. It is compressed with Brotli, and every current browser supports it. A single format("woff2") source is enough for nearly every site now; old formats such as WOFF, TTF and EOT were needed only for browsers few people still use. The format() hint lets a browser skip a file it cannot read without downloading it. Font files you download from a foundry or from Google are often TTF; the video shows converting them to WOFF2 with a tool.
Hosted or self-hosted
Services like Google Fonts give you a <link> and a font that is already optimized. Self-hosting means copying the files into your project. Reasons to self-host:
- Performance control: no additional domain to connect to, and you choose caching headers and preloading.
- Privacy: a request to a third-party font host sends visitors’ IP addresses to it. Kevin’s description says that for some sites in parts of Europe self-hosting may be the only choice.
- Reliability: nothing outside your deployment can change or fail.
The cost is that you maintain the files, subsets and updates yourself. Check the font’s license: most Google Fonts are open-licensed and can be self-hosted, but commercial fonts have their own terms.
What the video covers
Kevin Powell’s “Self-hosting fonts explained (including Google fonts) // @font-face tutorial” is about 16 minutes and is from February 2023. From its chapters: getting fonts from Google Fonts, the problem with the downloaded Google fonts, converting from .ttf to .woff and .woff2, adding fonts to a project, and setting up @font-face rules. Since 2023 WOFF is no longer worth shipping beside WOFF2, as noted above. I could not read a transcript, so the generic-family, synthesis and unicode-range explanations are from the lesson and not the video. The runner-up is a 2025 clip on font stacks.
Where this fits
Font stacks and @font-face are the base the rest of typography stands on, and the units you use for sizes come from values, units and math functions. The next lesson, variable fonts and font loading, covers one file with a whole range of weights and how to stop fonts from delaying or shifting the page. For fonts in a build pipeline, see web performance.
Check yourself
Why should every `font-family` declaration end with a generic family, e.g. `font-family: "Inter", Arial, sans-serif`?
If none of the named fonts is available, the generic keyword makes the browser pick some font of that style instead of the browser's default serif. It guarantees a sensible last resort, and it is the only part of the list that cannot fail.
You declare `@font-face` for "Brand" only at `font-weight: 400`, then set `<h1>` to `font-weight: 700`. What happens?
The browser has no bold file for that family, so it synthesizes a bold by smearing the regular glyphs. The result is usually heavier and uglier than a real bold. Declare a face for 700 (or a variable font range) to avoid it, or turn the synthesis off with `font-synthesis: none`.
What does `unicode-range` on an `@font-face` rule do?
It limits the face to the listed Unicode code points, so the file is downloaded only if the page contains a character in that range. It is how large fonts are split into subsets (Latin, Cyrillic, and so on) and loaded only when needed.
What are two reasons a team might self-host Google Fonts instead of linking to Google's CSS?
Control over caching, preloading and `font-display`, with no extra connection to another domain; and no third-party request that sends visitors' IP addresses to a font host, which matters in places with strict privacy rules. The video notes that for some European sites this may be the only option.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.