Fixing layout shifts caused by web fonts

Vincent Bernat

In 2020, Google in­tro­duced Core Web Vi­tals met­rics to mea­sure some as­pects of real-world user ex­pe­ri­ence on the web. This blog has con­sis­tently achieved good scores for two of these met­rics: Largest Con­tent­ful Paint and In­ter­ac­tion to Next Paint. How­ever, op­ti­miz­ing the third met­ric, Cu­mu­la­tive Lay­out Shift, which mea­sures un­ex­pected lay­out changes, has been more chal­leng­ing. Let’s face it: op­ti­miz­ing for this met­ric is not re­ally use­ful for a site like this one. But get­ting a bet­ter score is al­ways a good dis­traction. 💯

To pre­vent the “flash of in­vis­i­ble text” when us­ing web fonts, de­vel­op­ers should set the font-display prop­erty to swap in @font-face rules. This method al­lows browsers to ini­tially ren­der text us­ing a fall­back font, then re­place it with the web font af­ter load­ing. While this im­proves the LCP score, it causes con­tent re­flow and lay­out shifts if the fall­back and web fonts are not met­ri­cally com­pat­i­ble. These shifts neg­a­tively af­fect the CLS score. CSS pro­vides prop­er­ties to ad­dress this is­sue by over­rid­ing font met­rics when us­ing fall­back fonts: size-adjust, ascent-override, descent-override, and line-gap-override.

Two com­pre­hen­sive ar­ti­cles ex­plain each prop­erty and their com­pu­ta­tion meth­ods in de­tail: Cre­at­ing Per­fect Font Fall­backs in CSS and Im­proved font fallbacks.

Interactive tuning tool#

In­stead of com­put­ing each prop­erty from font av­er­age met­rics, I put to­gether a tool for in­ter­ac­tively tun­ing fall­back fonts.1

Instructions#

  1. Load your cus­tom font.

  2. Se­lect a fall­back font to tune.

  3. Ad­just the size-adjust prop­erty to match the width of your cus­tom font with the fall­back font. With a pro­por­tional font, it is not pos­si­ble to achieve a per­fect match.

  4. Fine-tune the ascent-override prop­erty. Aim to align the fi­nal dot of the last para­graph while mon­i­tor­ing the font’s base­line. For more pre­cise ad­just­ment, dis­able the “” option.

  5. Mod­ify the descent-override prop­erty. The goal is to make the two boxes match. You may need to al­ter­nate be­tween this and the pre­vi­ous prop­erty for op­ti­mal results.

  6. If nec­es­sary, ad­just the line-gap-override prop­erty. This step is typ­i­cally not required.

The process needs to be re­peated for each fall­back font. Some plat­forms may not in­clude cer­tain fonts. No­tably, An­droid lacks most fonts found in other op­er­at­ing sys­tems. It re­places Geor­gia with Noto Serif, which is not met­ri­cally com­patible.

Tool#

The tool re­quires JavaScript.

This tool is not avail­able from the Atom feed.

100%
100%
100%
0%

BGP con­fed­er­a­tion is a tech­nique used to re­duce the num­ber of in­ter­nal BGP ses­sions and im­prove scal­a­bil­ity in large au­ton­o­mous sys­tems (AS). It di­vides an AS into sub-ASes. Most eBGP rules ap­ply be­tween sub-ASes, ex­cept that next-hop, MED, and lo­cal pref­er­ences re­main un­changed. The AS path length ig­nores con­tri­bu­tions from con­fed­er­a­tion sub-ASes. BGP con­fed­er­a­tion is rarely used and BGP route re­flec­tion is typ­i­cally pre­ferred for scal­ing.
AS over­ride is a fea­ture that al­lows a router to re­place the ASN of a neigh­bor in the AS path of out­go­ing BGP routes with its own. It is use­ful when two dis­tinct au­ton­o­mous sys­tems share the same ASN. How­ever, it in­ter­feres with BGP’s loop pre­ven­tion mech­a­nism and should be used cau­tiously.

Results#

For the body text of this blog, I get the fol­low­ing CSS def­inition:

@font-face {
  font-family: Merriweather;
  font-style: normal;
  font-weight: 400;
  src: url("../fonts/merriweather.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Fallback for Merriweather";
  src: local("Noto Serif"), local("Droid Serif");
  size-adjust: 98.3%;
  ascent-override: 99%;
  descent-override: 27%;
}
@font-face {
  font-family: "Fallback for Merriweather";
  src: local("Georgia");
  size-adjust: 106%;
  ascent-override: 90.4%;
  descent-override: 27.3%;
}

font-family: Merriweather, "Fallback for Merriweather", serif;

Up­date (2026-10)

I switched from Mer­ri­weather to Lit­er­ata for body text.

Af­ter a month, the CLS met­ric im­proved to 0:

Core Web Vitals scores for vincent.bernat.ch showing all 6 metrics as green.
Notably the Cumulative Layout Shift is 0.
Recent Core Web Vitals scores for vincent.bernat.ch

About custom fonts#

Us­ing safe web fonts or a mod­ern font stack is of­ten sim­pler. How­ever, I pre­fer cus­tom web fonts. Mer­ri­weather and Io­sevka, which are used in this blog, en­hance the read­ing ex­pe­ri­ence. An al­ter­na­tive ap­proach could be to use Geor­gia as a serif op­tion. Un­for­tu­nately, most de­fault monospace fonts are ugly.

Fur­ther­more, para­graphs that com­bine pro­por­tional and monospace fonts can cre­ate vis­ual dis­rup­tion. This oc­curs due to mis­matched ver­ti­cal met­rics or weights. To ad­dress this is­sue, I ad­just Io­sevka’s met­rics and weight to align with Mer­ri­weather’s char­ac­teristics.