Interaction & Visual Craft

A 55% size-adjust on a local font solves the broken-webfont headline problem

When a web font fails to load, oversized headings render in system-ui and break the layout. A local @font-face registration with size-adjust: 55% fixes the mismatch.

  • AuthorJames Calloway
  • ChannelInteraction & Visual Craft
  • Filed
  • Read3 min
A 55% size-adjust on a local font solves the broken-webfont headline problem
jamesmarkosborne / pixabay
  • The fix uses size-adjust: 55% on system-ui registered via local() in @font-face
  • The original heading size was clamp(3.13rem, 2.74vw + 2.75rem, 5.38rem)
  • The web font is a variable woff2 covering weights 200–700 with font-display: swap
  • if() can't help: its style(), media() and supports() conditions can't detect font load failures

A heading set with clamp(3.13rem, 2.74vw + 2.75rem, 5.38rem) looked fine in the web font — and then the font file failed to load. That is the starting point of a practical write-up on font fallbacks, and the fix it lands on is a single CSS descriptor: size-adjust, set to 55%, applied to a locally registered copy of system-ui.

The scenario will sound familiar to anyone who has shipped a variable web font. You register it with @font-face, point the src at a woff2 file, set font-display: swap and a weight range of 200 to 700. Then you declare it on the headings with a fallback stack:

:where(h1, h2, h3, h4, h5, h6) {
  font-family: "NewFont", system-ui;
}

So far, so conventional. But the new typeface needs larger sizes than the UA defaults, because its default sizing runs small. The moment the woff2 request fails — network hiccup, CDN outage, file path typo — the browser swaps in system-ui, and every heading on the page suddenly renders at the enlarged clamp value in a face that was never designed to take it. The author's description is blunt: "Oh gosh, that's huge. That doesn't suit my UI at all."

Why can't CSS just detect the failure?

The obvious first instinct was the experimental if() function. It doesn't work here. The conditions if() accepts — style(), media(), and supports() — can only query what the browser already knows about the page and its environment. There is simply no condition that tells the browser "this font request failed," so the branch you'd want to write has nothing to hang on.

The workaround comes from a property of @font-face that most developers underuse: it can register any font, including local ones, under a custom family name.

@font-face {
  font-family: "NewFont Fallback";
  src: local("system-ui");
  size-adjust: 55%;
}

With that rule in place, the heading stack becomes:

:where(h1, h2, h3, h4, h5, h6) {
  font-family: "NewFont", "NewFont Fallback", sans-serif;
}

What does the 55% actually do?

size-adjust scales the glyphs of the font it's attached to. Registering system-ui locally and knocking it down to 55 percent — a value the author arrived at by "a little eyeball testing" — compensates for the oversized clamp-based font-size, so the fallback roughly matches what the web font would have rendered at the same size. The trailing sans-serif in the stack covers the edge case of a machine that has no system-ui font at all.

The technique also works in reverse: instead of shrinking the fallback, you could use size-adjust to scale the fallback up to meet a web font that runs small. Either direction points at the same insight — conventional wisdom says to choose the web font that best matches your custom font, but the fallback side of the stack deserves deliberate sizing decisions too, not just a family name.

To verify the result, the author suggests removing "NewFont" from the stack entirely and reloading: the page then renders in the adjusted fallback, which is the exact state users on a failed font request will see.

One caveat worth holding onto: 55% is specific to this font pairing, not a magic number. Every pairing needs its own calibration, and @font-face offers many more matching descriptors — ascent-override, descent-override, line-gap-override among them — for anyone more persnickety about optical matching. As browser support for the if() function matures, some of this manual calibration could eventually fold into conditional CSS, but until a condition can see font load failures, size-adjust on a locally registered fallback remains the reliable answer.

Source: CSS-Tricks

More from James Calloway

James Calloway

Show full bio

Senior reporter covering regulation, policy and their impact on Product and interaction design, design systems at Interface Wire.

195 articles

Related articles

« Previous articleNext article »