Font Loading & CLS Mechanics
Webfonts are not discovered until the engine builds both the DOM and CSSOM, leaving text either invisible (FOIT) or jumping when the font arrives (FOUT/CLS). Combine font-display: swap or optional with size-adjust and ascent-override on a local fallback @font-face to lock glyph dimensions.
Font Fallback: Unadjusted Swap vs Metric-Matched Swap
Compare raw font-display: swap reflow against size-adjust + ascent-override metric alignment.
@font-face {
font-family: 'BrandSans';
src: url('/fonts/brand.woff2') format('woff2');
font-display: swap;
}Fallback Arial wraps differently, shifting every paragraph below the heading.
@font-face {
font-family: 'BrandSansFallback';
src: local('Arial');
size-adjust: 104.2%;
ascent-override: 92%;
}Fallback glyphs occupy the exact bounding box of the incoming webfont.
Under the Hood
Font loading behaves like swapping a theater understudy mid-monologue: if the understudy is three inches shorter than the lead actor, the entire stage lighting rig has to be re-measured on the spot, triggering a full Layout pass.
- The browser discovers font URLs only after parsing CSS and matching
@font-facerules to visible text nodes, unless hinted via the Preload Scanner. font-displaysets two timers: a block period (invisible text) and a swap period (swap: 100 ms block, infinite swap;optional: 100 ms block, 0 ms swap).- When the WOFF2 arrives during the swap window,
size-adjust,ascent-override, anddescent-overrideensure the fallback system font occupied the exact same line height and width.
@font-face {
font-family: "InterFallback";
src: local("Arial");
size-adjust: 107%;
ascent-override: 90%;
descent-override: 22%;
line-gap-override: 0%;
}Problem Genealogy
- 2010 (
@font-faceFOIT): Browsers hid text for up to 30 seconds on slow networks, turning articles into blank white rectangles. - 2017 (
font-display: swap): Eliminated invisible text, but traded FOIT for violent layout shifts whenever custom fonts were wider than Arial. - 2021+ (Metric Overrides &
font-display: optional): Addedsize-adjustandascent-override, letting fallback fonts impersonate webfont geometry down to the pixel.
Production Pitfalls
- Preloading 6 font weights: Preloading every weight and italic variant starves hero images and CSS on the initial connection; preload at most 1–2 primary WOFF2 files.
- Missing
unicode-rangesubsetting: Shipping a 400 KB full-Unicode font when visitors only read Latin characters wastes bandwidth; split subsets viaunicode-range.
- When not to use
font-display: swap: For body copy where zero visual flash matters more than brand typography on first visit, usefont-display: optionalso slow connections stick with the fallback cleanly.
Connections & Logical Next Steps
Capturing screenshots before document.fonts.ready produces fallback-font diffs and layout shifts.
Preloading critical WOFF2 subsets starts font downloads before CSSOM parsing finishes.
Swapping mismatched font metrics forces a synchronous layout recalculation across text nodes.
Late webfont swaps without metric overrides are a primary driver of CLS.