Sub topic 5
Writing font-family stacks with fallbacks
A font-family stack is an ordered list of font names. The browser uses the first one it can render and moves down the list when one is missing. This chapter covers how the browser resolves the list, how to write stacks that degrade gracefully, and the mistakes that cause silent failures. It assumes you know basic HTML structure and the link element, CSS selectors and the font-family property, and how to open your browser's developer tools.
Why every web font needs a stack
A web font from Google Fonts or Adobe Fonts is not guaranteed to be on screen. The file may still be downloading, the request may be blocked by a network filter, or a visitor may have disabled web fonts. If your CSS names only one font, the browser falls back to its default, which is usually a serif font you did not choose.
A stack gives you control over that failure. You decide which fonts appear instead, in what order, and how closely they match your intended design.
body {
font-family: "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}This stack has five kinds of entry:
"Inter"is the web font you loaded.system-uiis a generic keyword for the operating system's interface font.-apple-systemis an older name for the system font in Safari on Apple platforms."Segoe UI"is the Windows interface font.Arialis a widely installed font.sans-serifis the generic family that guarantees some sans-serif font.
How the browser walks the stack
The browser reads the list from left to right. For each name it checks whether a matching font is available, either installed on the device or declared by an @font-face rule, which Google Fonts and Adobe Fonts generate for you. The first match is used. If the match lacks a glyph for a character, such as an emoji or a Cyrillic letter, the browser continues down the list for that character only. Fallback therefore works per character, not per page.
A web font that is still downloading counts as unavailable for the first render, unless the browser is told to wait. How long the browser waits depends on font-display, which a later chapter covers. For now, remember that the fallback fonts in your stack are what visitors see first on a slow connection.
The parts of a good stack
Quoting rules
Font names that contain spaces, digits, or punctuation should be quoted. Generic family keywords must not be quoted.
"Segoe UI"is correct. Unquoted multi-word names are legal in some cases, but quoting avoids parsing surprises."Source Sans 3"needs quotes because of the digit.sans-serifis a keyword. Writing"sans-serif"makes the browser look for a font literally named sans-serif, which does not exist, so the keyword's meaning is lost.
Generic families
Every stack should end with a generic family. It is the final safety net, since the browser always has some font for it. The ones you will use most are:
| Keyword | Meaning | Typical use |
|---|---|---|
| `serif` | Fonts with small strokes on letter ends | Long-form reading, editorial headings |
| `sans-serif` | Fonts without those strokes | Interfaces, body text |
| `monospace` | Every character has the same width | Code, tabular output |
| `system-ui` | The operating system's interface font | Native-feeling UI text |
| `ui-monospace` | The system's monospace font | Code blocks that match the OS |
| `cursive`, `fantasy` | Decorative styles, inconsistent across systems | Rarely, and only as a last entry |
Pick the generic family that matches the category of your main font. A serif web font should fall back to serif, not sans-serif, so the page keeps roughly the same character if the web font fails.
Order of the entries
A reliable order is:
- The web font you loaded.
- One or more system fonts with similar proportions.
- A widely available font such as Arial or Georgia.
- The generic family.
Place the web font first so it wins whenever it loads. Keep the system fonts close in width and x-height (the height of lowercase letters) to the web font. The closer they are, the less the text shifts when the web font arrives.
Stacks for the three common roles
:root {
--font-body: "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
--font-heading: "Merriweather", Georgia, "Times New Roman", serif;
--font-code: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, "Courier New", monospace;
}
body {
font-family: var(--font-body);
}
h1,
h2,
h3 {
font-family: var(--font-heading);
}
code,
pre {
font-family: var(--font-code);
}Putting each stack in a custom property means you write it once and change it in one place. It also keeps the stack the same everywhere, which matters because a heading that falls back to a different family than the body can look broken.
Using the exact family name from each service
The name in your CSS must match the name the service defines. A mismatch causes no error. The browser simply treats it as an unavailable font and moves on.
For Google Fonts, the CSS family name is the one shown in the catalog, such as "Inter". The link tag from the embed code makes that name available:
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">For Adobe Fonts, the CSS name is often a lowercase, hyphenated slug that differs from the marketing name. The project page lists it. This rule assumes your project includes Proxima Nova at weight 700:
h1, h2 {
font-family: "proxima-nova", Helvetica, Arial, sans-serif;
font-weight: 700;
}Copy the name from the project page instead of typing it from memory.
Reducing layout shift between fallback and web font
Fonts differ in how wide their letters are and how tall their lines run. When a web font replaces a fallback, text can reflow, and the page jumps. This is a layout shift, and it counts against the Cumulative Layout Shift metric.
You can reduce this by describing a local font as an adjusted fallback. The @font-face descriptors size-adjust, ascent-override, descent-override, and line-gap-override scale and align a local font so its metrics approximate the web font's.
@font-face {
font-family: "Inter Fallback";
src: local("Arial");
size-adjust: 107.6%;
ascent-override: 90.2%;
descent-override: 22.5%;
line-gap-override: 0%;
}
body {
font-family: "Inter", "Inter Fallback", system-ui, Arial, sans-serif;
}The adjusted font goes right after the web font, so it is the first fallback the browser tries. The percentages here are approximate values for pairing Inter with Arial. Tools that compare font metrics can calculate the right numbers for other pairs. Check browser support for these descriptors before relying on them, and treat the technique as an optimization, not a requirement.
Common errors
Quoting a generic keyword
font-family: "Inter", "sans-serif"; has no working generic fallback. Remove the quotes.
Forgetting the generic family
A stack ending in Arial works on most machines, but not on all. Always end with a generic keyword.
Using the `font` shorthand by accident
The font shorthand sets size, line height, weight, and family together, and it resets any property you leave out. Writing font: 16px Inter; clears an earlier font-weight or line-height. Use font-family when you only mean to change the family.
Form controls that ignore your font
Buttons, inputs, and text areas do not inherit font-family by default. They use the system's control font. Add this reset if you want them to match the page:
button,
input,
select,
textarea {
font: inherit;
}The lone monospace size quirk
Browsers apply a smaller default size (usually 13px instead of 16px) when the stack is exactly monospace and nothing else. Adding any other family name before it, as in the code stack above, avoids the quirk.
Assuming a fallback covers every script
system-ui and Arial cover Latin, Cyrillic, and Greek well, but they may lack glyphs for other scripts. If your audience uses another script, check that your web font supports it and that your fallbacks have reasonable coverage. The per-character rule means the browser will find some font for each character where one exists, though the mix may look uneven.
Misspelled names
A typo is silent. "Inter" and "Intr" both validate, and only the first one renders as intended. Check the rendered font in developer tools after any change.
A checklist for writing a stack
- Put the loaded web font first, spelled exactly as the service defines it.
- Add one or two system fonts that resemble it in width and height.
- Add a widely installed font such as Arial, Georgia, or Courier New.
- End with the generic family that matches the category.
- Quote names with spaces or digits, and never quote generic keywords.
- Define each stack once in a custom property and reuse it.
- Confirm the rendered font in developer tools, and test again with the network throttled and the web font blocked.
Exercise
A page loads Merriweather from Google Fonts, and the CSS reads h1 { font-family: "Merriweather", "serif"; }. Merriweather fails to load, and the heading appears in a sans-serif font on a visitor's device. Explain why, and write a corrected rule with a sensible fallback chain.
Show answer
Quoting "serif" turns the generic keyword into a font name. No font has that name, so the browser has no real generic fallback and uses its own default, which on this device was sans-serif. Remove the quotes and add intermediate fallbacks: h1 { font-family: "Merriweather", Georgia, "Times New Roman", serif; }.
Exercise
You inspect a heading in developer tools and the Rendered Fonts section shows Arial, even though your stack begins with "proxima-nova" from an Adobe Fonts project. List two likely causes.
Show answer
First, the Adobe project stylesheet link is missing, wrong, or blocked, so the font was never defined. Second, the name in the CSS does not match the name on the project page, or the project does not include the weight and style the rule requests, so the browser skipped it and used the next available entry.
Exercise
Why should you place an adjusted local fallback such as "Inter Fallback" directly after the web font, and not at the end of the stack?
Show answer
The browser tries entries in order, so the adjusted fallback is used only if it comes before the unadjusted system fonts. Placing it right after the web font means the first text the visitor sees already has metrics close to the web font's, which reduces the layout shift when the web font loads.