Skip to content

Your font fallback only works if the machine has Arial

5 min readProTechBridge

Our CogsIQ case study scored 0.097 for layout shift in PageSpeed's mobile test. Tested on a Mac, it scored 0. The page was the same in both places. The machines weren't, and the difference came down to one font.

The fallback is tuned for a font you might not have

Since we stopped preloading web fonts (the reason is in our last post), text paints first in a fallback font and switches to Inter when it arrives. next/font is meant to make that switch invisible. By default it generates a fallback face for each Google font, like this one from our built HTML:

@font-face {
  font-family: Inter Fallback;
  src: local(Arial);
  ascent-override: 90.44%;
  descent-override: 22.52%;
  line-gap-override: 0.0%;
  size-adjust: 107.12%;
}

The overrides scale Arial until its text takes up the same space as Inter's, so a paragraph wraps at the same words in both and nothing moves at the swap. It's a good idea with one dependency: local(Arial) only works if Arial is installed. Windows, macOS and iOS ship it. Many Linux machines don't.

When local() finds nothing, the face doesn't exist, and the browser moves on to the next font in the stack. On our site that is the system's own sans-serif, at its natural size, with none of the overrides. A font of a different width wraps at different words, the paragraph changes height when Inter arrives, and everything below it moves.

Hiding Arial reproduced PageSpeed's number exactly

We couldn't remove Arial from a Mac, so we hid it from the page instead. A Puppeteer script loaded each page at the screen size Lighthouse uses for mobile, held the font files back for a second so the swap landed after first paint, and rewrote local(Arial) in the HTML to a font name that exists nowhere.

Page Arial available Arial hidden PageSpeed, mobile
CogsIQ case study 0 0.097 0.097
Another product page 0 0.013 0.013
Collabrun case study 0 0.059 0.027, then 0

The two exact matches are what convinced us. The third row is a reminder that the swap only shifts anything if the font arrives after first paint, and that timing varies from run to run. The shift sources showed what moved: on CogsIQ, the intro paragraph re-wrapped and the row of buttons beneath it dropped about 30 pixels.

More fallback fonts made it worse

The obvious fix is to give local() more names to try. We wrote our own fallback faces listing Arial, then Arimo and Liberation Sans, which are metric-compatible Arial clones common on Linux, then Roboto, all with the same overrides.

It did nothing for the shift. CogsIQ still measured 0.097, so PageSpeed's machines evidently have none of those fonts, or not under those names. Worse, the products page, which had been scoring 98 on mobile, dropped to 82 and then 88, with its largest paint at 4.5 and 3.7 seconds. We reverted, and the next run scored 98 with the largest paint back at 1.7 seconds.

We didn't prove why. One local run hints at it: seven local() names that matched nothing pushed first paint from 516 ms to 724 ms, as if each failed lookup costs time before anything can be drawn. That is a single run, so treat it as a lead rather than a result. The idea had a quieter flaw too. The overrides were computed from Arial's metrics, which suits its clones, but on Roboto they would only ever have been roughly right.

Layout that doesn't care about the font held up

What did work was on another page. Its heading put the product name and a small "Live" badge on one line. In the fallback the badge fitted beside the name at phone width; in the display font, which runs wider, it dropped to a second line and pushed the page down 28 pixels. That happened with Arial present too, because the overrides match a font's average width, not the width of every word.

So we stopped asking whether it fits. On phones the badge now always sits on its own line under the name, and the heading is the same height whichever font is showing. That page's layout shift went from 0.199 to 0.013, and its mobile score from 89 to 99.

The general rule: anything whose layout depends on whether some text fits on a line will move when the font changes. A badge beside a heading, buttons that wrap next to a paragraph, a heading that only just fits its column. Fix the layout and the font can do what it likes.

What we left alone, and how to check yours

CogsIQ still scores 0.097 on PageSpeed, inside Google's 0.1 threshold for good, and 0 in our tests with Arial present. The remaining option is font-display: optional, which lets the browser skip the web font altogether when it arrives late. That would end the swap, at the cost of some first visits never seeing Inter, and it needs testing against the stall in our last post before we try it. For now we have left it.

To check your own site:

  • List the fallback faces your build generates. In a Next.js static export, grep -rho '@font-face{[^}]*Fallback[^}]*}' out/ | sort -u prints them. Any whose only source is local(Arial) behaves as described here.
  • In Chrome DevTools, use Local Overrides to change local(Arial) to a name that doesn't exist, throttle the network to Slow 4G so the font arrives after first paint, and record a reload in the Performance panel. It lists each layout shift and the elements that moved.
  • Fix what moved with layout, not with more font names.
  • Web performance
  • Fonts
  • Next.js

Need a hand with this in practice?

Reading about it is one thing. If you want someone to actually do it, that is what we are for.