font-display is one line of CSS that tells the browser what to do with your text while a web font is still downloading. Hide it? Show it in a stand-in font? Give up on the web font? There are five answers.
The two timers behind it
When a font is requested, the browser starts a timer. Web.dev and MDN describe three stages along it.12
- Block period. If the font hasn't loaded, text that uses it is drawn in an invisible fallback, so it can't be read yet.2
- Swap period. If the font still hasn't loaded, a visible fallback font is shown. If the real font turns up now, it's swapped in.2
- Failure period. The font is marked as failed and the fallback stays.2
The font-display value changes how long the first two stages last. You add it inside your @font-face rule.1
The five values side by side
| Value | What MDN says | In plain terms |
|---|---|---|
| auto | Browser's own choice3 | Differs between browsers |
| block | A short block period and an infinite swap period2 | Text hides for a moment, then the font can arrive at any time |
| swap | An extremely small block period and an infinite swap period2 | Fallback text at once, real font swaps in whenever it lands |
| fallback | An extremely small block period and a short swap period2 | Fallback text at once, but the real font only swaps in if it's quick |
| optional | An extremely small block period and no swap period2 | The font is used only if it's ready almost immediately |
The word "auto" leaves the choice to the browser. Without a setting, Chromium-based browsers and Firefox block text for up to 3 seconds, and Safari blocks it indefinitely.3 That's why a missing setting can mean an empty page for a while.
Which one suits whom
web.dev says it's hard to recommend one approach, because it depends on taste, on how important the font is to your brand, and on how jarring a late swap looks.3 It does lay out three trade-offs.
swap suits a site where seeing text fast matters most, but the web font should still appear. The downside is a jarring shift when the font arrives late.3
optional suits a site that cares most about speed and stability. The downside is that the web font won't be used if it arrives late.3 In that case visitors see your fallback font instead.
block suits a site that wants text to appear in the web font only. The first display of text is delayed.3
You can mix them. web.dev's example is swap for branding and eye-catching parts of a page, and optional for body text.3
A starting point, not a rule
Here's a simple way to decide. If your heading font is part of how people recognise you, swap keeps it. If your body font is just a nicer-looking text face, optional stops it jumping around. Both choices come from the trade-offs above, so you can change them as you see how your pages behave.
swap and optional don't fix a slow font. They only decide how a slow font is treated.2 Smaller files help with the rest, so look at which file formats you need and how many fonts and weights you load. For the text moving around, see why text flashes or jumps.
Cited material
- Optimize WebFont loading and rendering, web.dev (Google)
- font-display, MDN Web Docs (Mozilla)
- Best practices for fonts, web.dev (Google)
