Two different things get mixed up here, and they have different fixes. Text can flash, meaning it's missing or changes look. Or the page can jump, meaning other content moves. You can have either, both or neither.
Flash: the text isn't there, or it changes
If the font hasn't arrived, the browser may not draw any text yet.1 If a stand-in font is shown first and the real one replaces it, the text changes look. The table sets out each case.
| What you see | What's going on | Setting that controls it |
|---|---|---|
| Blank gap where text should be | The browser is waiting for the font before drawing text1 | block and the browser default |
| Text appears, then changes look | A fallback font was drawn first, then replaced2 | swap, fallback |
| Text never changes | The web font arrived too late and wasn't used2 | optional |
Each setting is covered on the font-display page.
Jump: the page moves
A layout shift happens any time a visible element changes position from one rendered frame to the next.3 Fonts are one named cause: web.dev lists fonts that render larger or smaller than their fallback.3
The reason is plain. A web font and its fallback take up different amounts of space on the page. When one replaces the other, lines can come out longer or shorter, and everything below moves.2
Layout shifts are measured with a score called Cumulative Layout Shift. A good value is 0.1 or less.3 You don't need a number to spot one. If the paragraph you were reading drops down a line, that's a shift. Simple as that, and annoying.
Ways to reduce each one
Make the font arrive sooner. Faster delivery means faster text, and a font that comes early enough can avoid shifts from swapping.2 Smaller files help, and so does asking for fewer fonts. The fastest font to deliver is one that isn't requested at all.2
Choose a display value to match your goal. web.dev says optional guarantees no shifts caused by font swapping, but the web font may not be used. swap shows text quickly, but a late font causes a jarring shift.2
Make the fallback look more like the web font. The CSS size-adjust setting can be used to override the metrics of a fallback font so they better match the primary web font.4 web.dev points to the same setting for reducing the effect on layout shift.2 The details of matching a fallback properly are a topic for a later page here.
Which fix suits which problem
- Text invisible for a moment: pick
swaporoptional, or make the font arrive sooner.2 - Text changes look:
optionalavoids the change, but the web font may not be used.2 - Page moves:
optional, an early font, or a closer-matching fallback.24
Icon fonts are a special case. Their fallback typically looks very different and can mean something else, which makes shifts more likely. web.dev suggests replacing icon fonts with SVG pictures where possible.2
Is your own page affected? The DevTools page shows how to find out.
Cited material
- Optimize WebFont loading and rendering, web.dev (Google)
- Best practices for fonts, web.dev (Google)
- Cumulative Layout Shift (CLS), web.dev (Google)
- size-adjust, MDN Web Docs (Mozilla)
