Web font performance: subsetting, font-display and avoiding layout shift
Custom fonts make sites look distinctive, but they can slow pages and cause text to flash or jump as it loads. A few techniques keep typography fast.
1. Use fewer files. Every weight and style is often a separate download. Ask whether you truly need light, regular, medium, semibold, bold and their italics. A variable font may cover several weights in one file.
2. Use modern formats. WOFF2 offers good compression and broad modern browser support.
3. Subset. Remove characters you do not need, such as unused language sets. This can greatly reduce file size. Be careful if users might enter text in other languages.
4. Control loading behavior with font-display
- swap: shows fallback text immediately, then swaps to the web font. Good for readability, can cause a visible change.
- optional: uses the web font only if it loads very quickly; otherwise sticks with the fallback.
- Other values balance these trade-offs differently.
5. Preload critical fonts used above the fold so the browser fetches them early.
6. Reduce layout shift. Choose fallback fonts with similar metrics, and use CSS descriptors like size-adjust and ascent-override to match them more closely.
7. Self-host or use a CDN thoughtfully, considering caching, privacy and control.
Test with throttled network speeds to see the real experience.
Which technique made the biggest difference for your site? Do you prefer swap or optional?
Comments · 3
font-display: swap plus preloading the main weight fixes most layout jumps. Subsetting to Latin cuts file size hugely.
A well-chosen fallback with size-adjust can make the swap nearly invisible. Underused feature.
Variable fonts replace several files with one. Worth checking if your font has a variable version.