
Web Fonts Without Layout Shift
The page which jumps when the web font arrives, we all know it, so we made it jump on purpose, Verdana served as our web font with 800 ms delay, Arial as fallback, a narrow column of 520 pixels, and Chrome counting the layout shift.
Verdana is wider, we measured our text 115.2 percent of Arial. With font-display swap the text appeared in 60 ms in Arial and then moved when the font came, shift score 0.0212. With block there was the same shift 0.0212 and the LCP went to 900 ms, so we paid with invisible text and got nothing for it, this surprised us.
With optional the shift was 0 and the page simply stayed in Arial, our slow font was too late for the party and nobody saw it on this visit.
@font-face {
font-family: "Inter";
src: url("/fonts/inter-latin.woff2") format("woff2");
font-weight: 100 900;
font-display: swap;
}
Then the fix which we like, a second font-face which takes local Arial and has size-adjust 115.2 percent, and use it as fallback with swap. Shift 0, and the height of the page was exactly the same 1457 pixels as with Verdana, so the lines break in the same places and the swap happens without anybody noticing.
@font-face {
font-family: "Inter Fallback";
src: local("Arial");
size-adjust: 107%;
ascent-override: 90%;
descent-override: 22.5%;
line-gap-override: 0%;
}
body {
font-family: "Inter", "Inter Fallback", sans-serif;
}
The number 115.2 is only for our pair of fonts and our sentence, for yours measure it with canvas measureText or let a tool like Fontaine calculate, and remember ascent and descent overrides if the line height also moves, we did not need them here.
<link rel="preload" href="/fonts/inter-latin.woff2"
as="font" type="font/woff2" crossorigin>
See also: year-long cache header and web performance basics.