You open a website on an unstable signal. The photos are there, the buttons are there, but the words are blank. Two seconds later all the text appears at once. The page isn't broken. It was waiting for a font file.
A page can use two kinds of font. A system font is already installed on the user's device. A custom font (web font) is a font file that has to be downloaded before it can be used. Picture writing a name board. The marker in your drawer, like a system font, can be used right away. A nicer special marker, like a custom font, has to be bought at a shop first. While you wait, you have two choices: write with the drawer marker now and rewrite later, or leave the board blank until the new marker arrives. The browser has the same two choices for your text: show it first in a font it already has and replace it later, or leave it blank until the font file has downloaded.
System font: 0 bytes
In CSS, you choose a font with the font-family property. For a system font, one line is enough:
body { font-family: system-ui, sans-serif; }
system-ui is the modern CSS font-family value meaning "this device's interface font", the font the device uses for its own menus and apps. It is San Francisco on iPhones and Macs, Segoe UI on Windows, and usually Roboto on Android. The sans-serif after it is the fallback in case the browser doesn't know system-ui. Before system-ui existed, people wrote a long list: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif.
Its cost: 0 bytes, 0 requests. A byte is a unit of file size, and a request is the browser asking a server (the computer that stores the website's files) for a file. Text shows right away, and users are already used to its letter shapes. The downside is that your page looks slightly different on every device, and has no character of its own.
Custom font: how many bytes the guest pays
Suppose Mrs. Sri wants her page in Poppins, a free font from Google Fonts. These are the file sizes of Poppins Regular (400), measured from Google Fonts (version v24):
| File version | Bytes | Compared with the row above |
|---|---|---|
| Full TTF, the old format | 154,628 | |
| Full WOFF2, the same file repackaged | 49,716 | 68% smaller |
| WOFF2, Latin letters only (subset) | 7,900 | another 84% smaller |
- WOFF2 is the smallest web font format. Its contents are compressed (packed to be smaller) with Brotli, and every modern browser supports it.
- A subset means the file only holds the characters you need. Full Poppins also has Devanagari letters for Hindi, but a page in English only needs Latin letters. Google Fonts already splits its fonts per subset, and the browser only downloads the subsets whose letters are on the page.
Bold (700) is a separate file: TTF 150,292 bytes, WOFF2 Latin 7,848 bytes. So for two weights: 304,920 bytes as TTF, or 15,748 bytes as WOFF2 Latin, 19 times smaller.
How long does the guest wait? A simple model: time ≈ one RTT (the round trip to the server) + bytes ÷ speed. With the "Slow 4G" setting of Lighthouse (Google's tool for measuring page speed), the speed is 1.6 Mbps (204,800 bytes per second, or 204.8 bytes per millisecond) and the RTT is 150 ms (milliseconds):
- WOFF2 Latin: 150 + 15,748 ÷ 204.8 = 150 + 77 = 227 ms.
- TTF: 150 + 304,920 ÷ 204.8 = 150 + 1,489 = 1,639 ms.
On a weak signal, 400 kbps (50,000 bytes per second) with a 400 ms RTT, the TTF takes 400 + 6,098 = 6,498 ms, and WOFF2 Latin 400 + 315 = 715 ms. A new connection to the font server adds more time, so these numbers are a minimum: the real wait can be longer.
font-display: what shows while waiting
While the font hasn't arrived, the browser does one of two things:
- FOIT (Flash of Invisible Text): the text is hidden. The page is there, but the room name and total are blank.
- FOUT (Flash of Unstyled Text): the text shows in a fallback font first, then switches to Poppins when its file arrives.
@font-face is a CSS rule that registers a font and its file. One of its settings, font-display, decides which one happens:
| Value | Text hidden | Switches to the custom font |
|---|---|---|
block |
up to 3 seconds | whenever the font arrives |
swap |
up to 100 ms, then the fallback font | whenever the font arrives |
fallback |
up to 100 ms | only if it arrives within about 3 seconds |
optional |
up to 100 ms | only if it arrives within those 100 ms, otherwise on the next visit |
auto |
the browser decides | usually the same as block |
Mrs. Sri's booking page uses Poppins without writing font-display. On a weak signal, do the room name and total show in the system font first, or not at all? The answer: not at all, for up to 3 seconds. Without font-display the value is auto (the last row of the table), and most browsers treat it like block. With the TTF on a weak signal, the guest stares at a page with no room name and no total for 3 seconds. Then the text appears in the fallback font, and it switches again at 6.5 seconds, when the TTF file arrives. With font-display: swap, the text shows in the system font within 100 ms, then switches to Poppins when the file arrives.
The code: loading Poppins properly
This is how to load Poppins from Google Fonts. The two <link> tags connect the page to files on another server, and <style> holds the CSS:
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap">
<style>
.mist { font-family: "Poppins", system-ui, sans-serif; }
</style>
wght@400;700loads only two weights. In Poppins every weight is a file of its own, so loading all nine weights means 9 files.display=swapmakes Google writefont-display: swapin every@font-face.preconnectopens the connection to the font file server early. This is needed because the CSS comes fromfonts.googleapis.com, but the font files come fromfonts.gstatic.com.system-ui, sans-serifafter Poppins is the fallback font shown while waiting.
That CSS file from Google is made of @font-face rules like the one below, one for each weight and each subset:
@font-face {
font-family: 'Poppins';
font-weight: 400;
font-display: swap;
src: url(https://fonts.gstatic.com/s/poppins/v24/pxiEyp8kv8JHgFVrJJfecnFHGPc.woff2) format('woff2');
unicode-range: U+0000-00FF; /* shortened: Latin letters */
}
If you store the font files on your own server (self-hosting), write the same @font-face, with src (the file's address) pointing at the WOFF2 file on your server.
The cost of swap: text moves. Suppose the fallback font is Arial. Poppins is wider than Arial. We measured one paragraph, 320px wide, in three browser engines: Chromium (the base of Chrome), Firefox and WebKit (the base of Safari). In Arial the paragraph has 5 lines (128px), in Poppins 6 lines (154px). When Poppins arrives, the paragraph grows by 26px, and everything below it jumps down. The fix is a fallback font enlarged with size-adjust (Chrome 92, Firefox 92, Safari 17):
@font-face {
font-family: "Poppins fallback";
src: local("Arial");
size-adjust: 112%;
}
.mist { font-family: "Poppins", "Poppins fallback", sans-serif; }
This code registers a new font called "Poppins fallback": the Arial already on the device (local("Arial")), at a larger size. With size-adjust: 112%, the same 320px paragraph also has 6 lines (154px) while it is still Arial, so nothing jumps. Other options:
| Option | When to pick it |
|---|---|
WOFF2 per weight + swap (the code above) |
1 to 3 weights. Mrs. Sri's page: 2 weights, 15,748 bytes |
| A variable font, for example Inter | many weights. Inter's Latin file from Google Fonts holds weights 100 to 900 in 48,432 bytes, so it saves bytes only when you use many weights |
font-display: optional |
the layout must not move at all. Poppins is used only if it arrives within 100 ms |
⚠️ Fonts that make the page slow or blank
- Forgetting
font-display. Theautovalue usually means invisible text for up to 3 seconds on a slow connection. - Loading every weight. In a font like Poppins, every weight is one file. Load only the ones your CSS uses.
- Using TTF or OTF on the web. Both are old font file formats. The same file as WOFF2 is 68% smaller.
- No fallback font. Always write
system-ui, sans-serifafter the custom font's name.
TL;DR: A system font (font-family: system-ui, sans-serif) is already installed on the device: 0 bytes, and it shows right away. A custom font has to be downloaded first. Poppins (a free font from Google Fonts) in weights 400 and 700 is 304,920 bytes as TTF, the old format, but only 15,748 bytes as WOFF2 Latin. So use WOFF2 (the compressed web font format), a Latin subset (Latin letters only), and only the weights you use. While waiting, FOIT hides the text, and FOUT shows a fallback font first. font-display controls the choice. block hides the text for up to 3 seconds, swap shows the system font first and switches when the custom font arrives, and optional only switches if the font arrives within 100 ms. Without font-display, most browsers behave like block, so write font-display: swap (or display=swap in the Google Fonts URL).
⚡ A system font: 0 bytes
Write:
body { font-family: system-ui, sans-serif; }
Meaning: font-family chooses the font. system-ui is the device's interface font, the font the device uses for its own menus: San Francisco on iPhones and Macs, Segoe UI on Windows. It is already installed, so it costs 0 bytes and 0 requests (no file is asked from a server), and the text shows right away. sans-serif is the fallback.
⚡ WOFF2, Latin letters, only the weights you use
Meaning: A custom font is a font file that has to be downloaded first, for example Poppins, a free font from Google Fonts. Poppins in weights 400 and 700 is 304,920 bytes as TTF (the old format). As WOFF2 (the compressed web font format) with only Latin letters, it is only 15,748 bytes, 19 times smaller. Load only the weights your CSS uses.
⚡ Don't leave the text blank
Write:
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap">
<style>
.mist { font-family: "Poppins", system-ui, sans-serif; }
</style>
Guess first: a page uses Poppins without writing font-display (the rule for what shows while the font downloads). On a weak signal, does the room name show in the system font first?
No, the text stays blank for up to 3 seconds. Without font-display the value is auto, and most browsers treat auto like block: the text is hidden first.
Meaning: display=swap in the Google Fonts address makes Google write font-display: swap. As a result, the text shows in the system font within 100 ms, then switches to Poppins as soon as its file arrives. preconnect opens the connection to the font server early. In .mist (the box around the whole booking page), system-ui, sans-serif after Poppins is the fallback font shown while waiting.