1. Home
  2. Practice
  3. font-display and CLS

font-display and CLS: keeping text from jumping

While a web font loads the browser has to show something. Your choice decides whether the text jumps.

Practice1 min readUpdated:
A monitor with code and a page layout next to a tablet

The font-display values

ValueBehaviour
blocka short invisible-text period, then swap
swapfallback font at once, swap after load
fallbacka very short block, limited swap period
optionalfont used only if it loads very quickly
autothe browser decides, usually like block

For body text swap or fallback are the usual choices. optional is useful where layout stability matters more than guaranteed use of the font.

Where layout shift comes from

When the fallback is replaced by the main font, letter widths and line heights change. Blocks reflow and elements below them move. This is measured by CLS (Cumulative Layout Shift); the recommended “good” threshold is 0.1 or less.

Align the metrics

The size-adjust, ascent-override, descent-override and line-gap-override descriptors let you declare a fallback that imitates the proportions of the main font:

@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia");
  size-adjust: 104%;
  ascent-override: 92%;
  descent-override: 24%;
  line-gap-override: 0%;
}

The values above are an example. Derive your own by measuring the actual rendering, because they depend on the font pair and platform.

Do not promise “zero shift” until you have measured. Test on a slow connection with the cache disabled.