Fallback font CSS without layout shift

Work out size-adjust and the metric overrides for a fallback font, so text does not jump when the web font loads.

The CSS

Paste it in your stylesheet: while the web font loads, Segoe UI is drawn in National Park with the same line length and line box.

Segoe UI → National Park
/* Official source: https://fonts.googleapis.com/css2?family=National+Park
   Host the font file yourself: download it from the source. */
@font-face {
  font-family: "National Park for Segoe UI";
  src: local("National Park"), url("/fonts/national-park.woff2") format("woff2");
  size-adjust: 99.7%;
  ascent-override: 108.24%;
  descent-override: 25.18%;
  line-gap-override: 0%;
}

body { font-family: "Segoe UI", "National Park for Segoe UI", sans-serif; }

Shift preview

The same paragraph at the same width: the original, the twin as it is, and the twin with the overrides.

OriginalCounting lines...

Quarterly report for the finance team. Invoices issued in March total 1,024 and all of them were paid within 30 days, which is 12 days faster than last year. The remaining balance is small, and the open items are listed on the second page.

Twin, no overridesCounting lines...

Quarterly report for the finance team. Invoices issued in March total 1,024 and all of them were paid within 30 days, which is 12 days faster than last year. The remaining balance is small, and the open items are listed on the second page.

Twin with overridesCounting lines...

Quarterly report for the finance team. Invoices issued in March total 1,024 and all of them were paid within 30 days, which is 12 days faster than last year. The remaining balance is small, and the open items are listed on the second page.

Counting lines...

Why size-adjust works

A web font swaps in late, and text shifts when its letters are wider or taller than the fallback's. size-adjust scales the fallback's glyphs so its English text has the same line length as the original, and ascent-override, descent-override and line-gap-override give it the original's line box. It changes the box of the twin only: the original is never touched, and when the real font arrives the lines stay where they were.