A font stack is the ordered list of family names you hand to font-family, and the browser takes the first one it can actually render — a family already installed on the machine, or a web font it can download. Ordering that list well and giving the web font a deliberate loading strategy is what stops text from arriving late and then jumping around.
This is the first lesson in the CSS Typography and Colors module, and the next lesson in this module is about "What Line Height and Scale Make Text Comfortable?".
What is a font stack, and how does the browser choose?
A font stack is nothing more than a comma-separated list of family names. The browser reads it from left to right and takes the first entry it can render. That entry counts as available in two situations: the family is installed on the user's machine, or you declared it with @font-face and the browser can fetch the file.
If nothing in the list resolves, the browser falls back to the generic family at the end — sans-serif, serif, monospace, cursive, fantasy, or the newer system-ui and ui-monospace. Generic families are not wildcards for anything; each one maps to whatever default the browser has configured. Keeping one at the end guarantees a usable face no matter what.
Two details catch people out. First, the stack inherits: setting font-family on body hands the same list to every descendant until something overrides it. Second, a family name containing a space must be quoted, so "Segoe UI" and "Helvetica Neue" need quotes while Arial does not.
How do you build a stack that survives every device?
Start with system-ui for interface text. It asks the operating system for its own interface font, so a reader gets the face their device already optimises for, with zero network cost. Follow it with a couple of widely available named faces, then the generic.
:root {
--font-ui: system-ui, -apple-system, "Segoe UI", Roboto,
"Helvetica Neue", Arial, sans-serif;
--font-serif: Georgia, "Times New Roman", serif;
--font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
body { font-family: var(--font-ui); }
.prose { font-family: var(--font-serif); }
code, pre { font-family: var(--font-mono); }
The -apple-system keyword is only understood by the systems that define it. Everywhere else the name is unknown, the browser skips it and moves on to the next entry, which is harmless but also pointless outside those systems. That is the general rule for the whole stack: an unknown name is skipped, never an error, so you can list generously without breaking anything.
Give headings and body copy different stacks only when the design truly needs it, and always give code its own monospace stack. Never ship a single family with no generic fallback. The browser will substitute silently on any machine that lacks it, and your line-height and spacing assumptions will be measured against a face you never chose.
How do you declare a web font?
@font-face creates a family name that CSS can then use and points that name at a real file. The src descriptor takes one or more url() sources, each with a format() hint so the browser can skip a file it cannot use and take the next one instead.
@font-face {
font-family: "Meridian";
src: url("/fonts/meridian-var.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
font-display: swap;
}
h1, h2 { font-family: "Meridian", Georgia, serif; }
Declaring font-weight: 100 900 tells the browser that one file covers the whole weight range, which is how a variable font is used. A static family has to be declared once per weight, each with its own src, otherwise the browser either picks the closest declared weight or synthesises a faux bold.
Fonts are always fetched in CORS mode, even from your own domain. If the font lives on a different origin than the page, that host must send Access-Control-Allow-Origin for the font, or the download is rejected and the browser falls back to the next family in the stack.
What does font-display actually change?
While a web font is in flight, the browser must show something. font-display chooses what, and for how long. There are four behaviours, and they trade layout shift against a blank screen.
- block hides the text for a short block period, then shows the fallback. No flash of fallback text, but invisible text and a later reflow.
- swap shows the fallback immediately and swaps in the web font when it arrives. Fastest first paint, at the cost of a visible reflow.
- fallback gives a very short block period, then a swap period, then keeps the fallback for the rest of the page's life.
- optional gives the font a very short window. If it misses it, the fallback is used and may never be replaced — the lowest layout shift, with no guarantee the brand font appears.
Whichever you pick, the reflow happens because the two faces have different metrics. You can remove most of that movement by declaring a fallback family whose metrics are overridden to match the web font.
@font-face {
font-family: "Meridian Fallback";
src: local("Arial");
size-adjust: 104%;
ascent-override: 92%;
descent-override: 24%;
line-gap-override: 0%;
}
body {
font-family: "Meridian", "Meridian Fallback", system-ui, sans-serif;
}
The overrides rescale the local Arial and substitute the web font's ascent, descent and line gap, so when the real face loads the text barely moves. The exact percentages depend on the pair of fonts, and you tune them by comparing the two side by side.
What actually makes a web font load fast?
The biggest win is not a clever property. It is refusing to download a file you do not need. Load only the weights you use, split the font into language subsets with unicode-range, and prefer one variable file over five static ones when the design allows it.
<link rel="preconnect" href="https://fonts.example.net" crossorigin>
<link rel="preload" href="/fonts/meridian-var.woff2" as="font"
type="font/woff2" crossorigin>
The crossorigin attribute on the preload is not optional decoration. Font requests are made in CORS mode, so a preload without it describes a different request from the one the browser will actually make, and the file is fetched twice or ignored entirely.
preconnect opens the connection to the font host early, which removes the handshake from the critical path when the host is far away. The preload starts the file download while the stylesheet is still being parsed, instead of waiting for the browser to read the CSS and discover the @font-face rule. Together they routinely remove hundreds of milliseconds from the time the text becomes visible.
Rules worth keeping
- A font stack is a fallback list, read left to right, and it should always end in a generic family.
system-uifirst is free speed for interface text; names it does not know are skipped, never fatal.- One
@font-faceper static weight, or one declaration with a weight range for a variable font. - Choose
font-displayknowingly: swap for speed, optional for zero shift, block if you can hide the text briefly. - Override the fallback metrics to stop the swap from reflowing the page.
- Preload with crossorigin, preconnect to the host, and subset the file before you optimise anything else.
Try it yourself: Build a font stack for a documentation site with three variables named --font-ui, --font-serif and --font-mono, each ending in a generic family. Then declare one web font with @font-face using font-display: swap, add a preload for the same file with crossorigin, and open DevTools to the Network tab with the font filter on. Reload the page and confirm you see exactly one request for the font file and that it starts before the stylesheet has finished loading.