Web Font Optimization: How Fonts Affect Loading, Rendering and Layout Stability
Fonts are a loading problem and a layout-stability problem at once. Subsetting, font-display, preload, and metric-matched fallbacks.
In short
Web fonts cause two different problems at once, and most advice only deals with one of them.
A loading problem. Fonts are discovered late — they are referenced from CSS, which itself has to download first — and until a font arrives, text using it is either invisible or shown in something else.
A layout stability problem. When the real font replaces the fallback, every line of text can change width and height, so the page shifts.
Fix only the first and you trade invisible text for a jumping page. The complete fix is four things: serve WOFF2 only, subset to the characters you use, set font-display: swap, and make your fallback font metrically similar so the swap is invisible.
How font loading actually works
The sequence is worse than people assume:
- The browser downloads your HTML.
- It finds and downloads your stylesheet.
- It parses the stylesheet and finds your
@font-facerules. - It works out which fonts are actually needed by the text on the page.
- Only then does it request the font file.
So a font is typically discovered two steps late, through no fault of yours. That is why preloading the one font that matters is worth doing, and why fonts referenced from a third-party stylesheet are slower still — that stylesheet is its own download, on its own connection.
What happens while it loads
The browser has a short block period during which text using the font is rendered invisibly, then a swap period during which a fallback is shown. font-display controls these.
| Value | Behaviour | Use when |
|---|---|---|
swap | Fallback shown immediately, swapped when ready | Almost always — text is never invisible |
optional | Very short block, and the browser may decide not to swap at all | Body text where you will accept the fallback permanently |
fallback | Short block, short swap window, then fallback stays | A middle ground |
block | Text invisible for up to about 3 seconds | Logos or wordmarks where the wrong font is unacceptable |
auto | Browser default, usually close to block | Leaving it unset is the problem |
FOIT (flash of invisible text) is what block gives you. FOUT (flash of unstyled text) is what swap gives you. FOUT is better for perceived speed and worse for layout stability — which the next section fixes.
Reducing what you load
WOFF2 only
WOFF2 is Brotli-compressed and supported by every browser you need to care about. Serving TTF, EOT or WOFF alongside it adds bytes and complexity for nothing.
@font-face {
font-family: 'Brand';
src: url('/fonts/brand-400.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
Ship only the weights you use
This is where most font weight hides. A family with four weights plus italics is eight files. Open your stylesheet and count what you actually reference — most sites use two or three.
A variable font can be a net win when you genuinely use several weights, because one file covers a range. If you use two weights, two static files are usually smaller.
Subset to the characters you need
A font covering every Latin script, plus Cyrillic and Greek, is far larger than one covering the characters your site displays.
@font-face {
font-family: 'Brand';
src: url('/fonts/brand-400-latin.woff2') format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2212;
font-display: swap;
}
unicode-range lets the browser skip downloading a subset entirely if no character on the page needs it. Be careful not to subset away characters you do use — currency symbols, accented names, and the typographic quotes and dashes a CMS inserts automatically are the usual casualties.
Self-host rather than using a font CDN
A third-party font host costs a DNS lookup, a connection and a TLS handshake before the font is even requested, and the stylesheet it serves is itself a blocking download. Self-hosting removes all of that and lets you control caching and font-display.
Check the licence allows it — most open fonts do.
Preload the one that matters
<link rel="preload" href="/fonts/brand-400-latin.woff2" as="font" type="font/woff2" crossorigin>
This removes the discovery delay by requesting the font immediately. Two rules: crossorigin is required even for same-origin fonts or the preload is wasted and the font downloads twice, and preload one font, not all of them — preloads compete for bandwidth with each other and with your main image.
Fixing the layout shift
This is the half usually left out, and it is why swap alone is not the answer.
When the fallback is replaced by your font, the text re-renders. If the two fonts have different character widths and line heights, everything moves. On a text-heavy page that can dominate your CLS.
The fix is a fallback @font-face whose metrics are adjusted to match your real font:
/* The real font */
@font-face {
font-family: 'Brand';
src: url('/fonts/brand-400-latin.woff2') format('woff2');
font-weight: 400;
font-display: swap;
}
/* A local fallback, adjusted so it occupies the same space */
@font-face {
font-family: 'Brand fallback';
src: local('Arial');
size-adjust: 97%;
ascent-override: 90%;
descent-override: 22%;
line-gap-override: 0%;
}
body {
font-family: 'Brand', 'Brand fallback', Arial, sans-serif;
}
size-adjust scales the fallback's glyphs; the ascent, descent and line-gap overrides make its line box match. Tune the percentages by comparing screenshots taken at the moment of swap until nothing moves.
How to find the right numbers: load the page with the real font blocked (DevTools → Network → block the font URL), screenshot it, then unblock and screenshot again. Adjust until the two match. Several tools can calculate the overrides from a font file, which is quicker than doing it by eye.
A note on icon fonts
An icon font is a font file downloaded to draw shapes, and it carries all of the problems above plus accessibility ones. SVG icons are smaller, render immediately, do not shift layout, and can be inlined. If you are still shipping an icon font, replacing it is usually a larger win than optimising it.
Platform differences
Shopify. The platform font system handles loading behaviour for its own fonts. Hand-written @font-face rules in a theme usually do not, so check what your theme actually does. Fonts uploaded to theme assets can be preloaded with the preload_tag filter.
WordPress. Themes and plugins frequently each load their own fonts, so a page can download three families nobody chose deliberately. Check what is enqueued before optimising what you know about.
Custom builds. Everything here is available. Self-host, subset at build time, preload one file, and match fallback metrics.
Hosted builders. Custom fonts can usually be uploaded, but font-display and preload are often not controllable. Your lever is how many families and weights you use.
Common mistakes
Leaving font-display unset, which means invisible text for up to three seconds.
Using swap without matching fallback metrics, trading invisible text for layout shift.
Preloading every font. They compete, and your main image loses.
Preloading without crossorigin, which wastes the preload and downloads the font twice.
Loading weights you never use.
Subsetting too aggressively and losing currency symbols, accented characters or typographic punctuation.
Using a third-party font host when self-hosting is permitted.
Using an icon font instead of SVG.
Testing with a warm cache, where the font is already local and nothing swaps.
Verification
- Reload with throttling and an empty cache, and watch the headings. Text should appear immediately in the fallback.
- Check for layout shift at the swap. Switch on Layout Shift Regions in the Rendering panel — the swap moment should not flash.
- Compare screenshots with the font blocked and unblocked. They should be nearly identical in layout.
- Check the font file count and total size in the Network panel. Fewer, smaller files than before.
- Confirm the preload was used, not wasted — a font requested twice means the preload did not match (usually a missing
crossorigin). - Check your characters render. Currency symbols, accented names, curly quotes, em dashes.
- Check LCP if your LCP element is text, since it may have been waiting on the font.
- Then watch field CLS and LCP over four weeks.
When it still does not improve
- Text still invisible briefly →
font-displayis not applied to every@font-face, or a plugin or theme is loading its own fonts without it. - Layout still shifts at the swap → the fallback metrics are not close enough. Adjust
size-adjustin small steps and compare screenshots. - The font downloads twice → the preload does not match the
@font-facerequest. Checkcrossoriginand that the URL is identical. - LCP got worse after preloading → the font preload is competing with your main image. Preload one or the other, and usually the image should win.
- A character renders in the wrong font → your subset excludes it. Widen the
unicode-range. - Fonts you did not add are loading → a plugin, theme or app. Find and remove them before tuning your own.
Keeping it fixed
Font weight creeps back through design decisions: a new weight for a campaign, a second family for headings, an icon font added by a plugin.
Three habits: keep the list of families and weights short and written down, require that any new font comes with font-display and matched fallback metrics, and include the swap moment in your layout-stability check before release.
Frequently asked questions
What is the best font-display value?
swap for almost everything — text renders immediately in a fallback and swaps when the font arrives, so it is never invisible. Use optional for body text where you will accept the fallback permanently, and block only for a logo or wordmark where the wrong font is unacceptable. Leaving it unset means invisible text for up to about three seconds.
Do web fonts cause layout shift?
Yes, when the fallback is replaced. If the two fonts have different character widths and line heights, every line of text changes size and position. Fix it with a fallback @font-face using size-adjust and the ascent, descent and line-gap overrides so the fallback occupies the same space.
Should I preload my fonts?
Preload the one font that matters most, not all of them — preloads compete for bandwidth with each other and with your main image. And always include crossorigin, even for same-origin fonts, or the preload is wasted and the font downloads twice.
Is it better to self-host fonts or use Google Fonts?
Self-hosting is generally faster where the licence allows it. A third-party font host costs a DNS lookup, connection and TLS handshake before the font is even requested, and the stylesheet it serves is its own blocking download. Self-hosting also lets you control caching and font-display.
What font formats do I need to serve?
WOFF2 only. It is Brotli-compressed and supported by every browser worth supporting. Serving TTF, EOT or WOFF alongside it adds bytes and complexity for nothing.
Should I use an icon font?
Generally no. An icon font is a font file downloaded to draw shapes, so it carries every font loading problem plus accessibility ones. SVG icons are smaller, render immediately, do not shift layout, and can be inlined.
References
- Best practices for fonts — web.dev
- font-display — MDN
- size-adjust — MDN
- unicode-range — MDN
- Optimize Cumulative Layout Shift — web.dev