font-display
Example
body {
font-family: "Brand", sans-serif;
font-display: swap;
}@font-face {
font-family: "Brand";
src: url("brand.woff2") format("woff2");
font-display: swap;
}font-display is a descriptor of @font-face; as a regular property on body it is ignored.
Common mistakes
- Text is invisible for a few seconds on slow networks because the default is
auto. - The layout jumps when the web font swaps in, because the fallback font has different metrics.
Key points
font-displayis set inside each@font-faceblock, not on regular selectors.- Web fonts use
swaporoptionalso text is visible while the font loads. - Critical fonts are preloaded with
crossorigin, so the swap happens early.
Interview questions
font-display swap vs optional?
swap shows fallback text and always switches when the font loads. optional uses the font only if it arrives almost immediately, avoiding a late layout shift.
Does font-display: swap cause layout shift?
It can, when the fallback and web font differ in size. Tune the fallback with size-adjust in @font-face to reduce it.