Network & PerformanceBaseline · Widely

Font Loading & CLS Mechanics

Mental Model

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.

Interactive Simulator

Font Fallback: Unadjusted Swap vs Metric-Matched Swap

Compare raw font-display: swap reflow against size-adjust + ascent-override metric alignment.

Lines of Code
Before
5
After
6
Reflows / Browser Cost
Before
CLS 0.18 on glyph swap
After
CLS 0.002 on glyph swap
BeforeUnadjusted Fallback (Causes CLS on Swap)
@font-face {
  font-family: 'BrandSans';
  src: url('/fonts/brand.woff2') format('woff2');
  font-display: swap;
}
Lines: 5Reflows: CLS 0.18 on glyph swapDependencies: System Arial fallback mismatch

Fallback Arial wraps differently, shifting every paragraph below the heading.

After (Native)Metric-Matched Fallback (Near-Zero CLS)
@font-face {
  font-family: 'BrandSansFallback';
  src: local('Arial');
  size-adjust: 104.2%;
  ascent-override: 92%;
}
Lines: 6Reflows: CLS 0.002 on glyph swapDependencies: CSS Fonts Level 5 descriptors

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.

  1. The browser discovers font URLs only after parsing CSS and matching @font-face rules to visible text nodes, unless hinted via the Preload Scanner.
  2. font-display sets two timers: a block period (invisible text) and a swap period (swap: 100 ms block, infinite swap; optional: 100 ms block, 0 ms swap).
  3. When the WOFF2 arrives during the swap window, size-adjust, ascent-override, and descent-override ensure the fallback system font occupied the exact same line height and width.
CSS
@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-face FOIT): 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): Added size-adjust and ascent-override, letting fallback fonts impersonate webfont geometry down to the pixel.

Production Pitfalls

Production Pitfall
  • 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-range subsetting: Shipping a 400 KB full-Unicode font when visitors only read Latin characters wastes bandwidth; split subsets via unicode-range.
When Not to Use
  • When not to use font-display: swap: For body copy where zero visual flash matters more than brand typography on first visit, use font-display: optional so slow connections stick with the fallback cleanly.

Connections & Logical Next Steps