Custom fonts make a brand recognisable, but loaded carelessly they hide text for seconds (a flash of invisible text) or make every line jump when they arrive (layout shift). Both are avoidable.
What goes wrong
- The browser builds the page and finds text that uses a web font.
- It requests the font file, which may take hundreds of milliseconds on mobile.
- Meanwhile it either hides the text or shows it in a fallback font.
- When the web font arrives, text re-renders. If the fallback had different letter widths, lines rewrap and the page shifts.
1. Show text immediately with font-display
@font-face {
font-family: 'Brand Sans';
src: url('/fonts/brand-sans.woff2') format('woff2');
font-display: swap;
}
swap shows the fallback at once and swaps when ready. optional goes further: if the font is not ready almost immediately, the fallback is used for that page view, which removes the swap entirely on slow connections.
2. Make the fallback the same size
The shift happens because the fallback font is wider or narrower. Modern CSS lets you adjust a local font to match:
@font-face {
font-family: 'Brand Sans Fallback';
src: local('Arial');
size-adjust: 104%;
ascent-override: 92%;
descent-override: 24%;
}
body { font-family: 'Brand Sans', 'Brand Sans Fallback', system-ui, sans-serif; }
Frameworks such as Next.js generate these values automatically when you use their font loaders.
3. Preload the fonts you need above the fold
<link rel="preload" href="/fonts/brand-sans.woff2" as="font" type="font/woff2" crossorigin>
Preload only the one or two files used in the first screen; preloading everything competes with images and CSS.
4. Ship less font
- WOFF2 only. Every current browser supports it.
- Subset to the characters you use (for example Latin only).
- Fewer weights. Regular, medium and semibold are usually enough. A variable font can replace several files.
5. Self-host when you can
Fonts from a third-party domain need an extra connection. Self-hosting, or a framework that downloads fonts at build time, avoids it and keeps visitors' IP addresses away from the font provider.
Check your work
- Throttle the network in DevTools and reload: text should appear at once, without a visible jump.
- Watch CLS in your field data for a week after the change.
You can check how fonts affect load time on any page with the free LCP test.
What is the best font-display value?
swap is a safe default because text shows immediately. optional removes the swap on slow connections at the cost of sometimes not showing the web font.
Why do fonts cause layout shift?
The fallback font has different letter widths, so text rewraps when the web font arrives. Size-adjusted fallbacks prevent it.
Should I preload all my fonts?
No. Preload only the one or two files used in the first screen.
Try VitalRix free
Uptime monitoring, APM, logs, real user monitoring and status pages in one place. No credit card needed.