Metric-Matched Fallback Fonts with size-adjust
When a web font loads with font-display: swap, the browser first renders text in a fallback font, then re-renders it in the web font when the file arrives. If the two fonts have different widths and line heights, every paragraph reflows at the moment of swap: lines rewrap, blocks change height, and everything below moves. That movement is layout shift, and on text-heavy static sites it is often the largest single contributor to CLS.
The fix is to stop using the fallback font as it comes. Four @font-face descriptors — size-adjust, ascent-override, descent-override and line-gap-override — let you define a new face that uses a local font's glyphs with the web font's measurements. This guide explains what each descriptor does, how to calculate the values, and how to generate them in the build. It is part of Font Loading Strategies for Static Sites.
Prerequisites
- A self-hosted web font you can read metrics from.
- A build step that can run Node.js, or willingness to calculate the numbers once by hand.
- Field or lab CLS data showing text reflow when fonts swap — see Eliminating Layout Shift from Web Fonts.
Why the Swap Moves Text
Two properties of a font decide how much space a paragraph takes: the average advance width of its characters, which controls how many words fit on a line, and its vertical metrics, which control the height of each line box. Inter and Arial at the same font-size differ on both. Inter is wider, so a paragraph set in Arial wraps later and has fewer lines; Inter's ascent and descent are also larger, so each of those lines is taller.
The Four Descriptors
All four go inside an @font-face rule that uses local() as its source, creating a new family name that you place in the font stack between the web font and the generic fallback.
@font-face {
font-family: 'Inter Fallback';
src: local('Arial'), local('Helvetica'), local('Liberation Sans');
size-adjust: 107.12%;
ascent-override: 90.44%;
descent-override: 22.52%;
line-gap-override: 0%;
}
body {
font-family: 'Inter', 'Inter Fallback', sans-serif;
}
size-adjustscales the glyphs and their advance widths. It is the main control for how many words fit on a line.ascent-overridesets the height above the baseline used for line box calculation, as a percentage of the used font size.descent-overridedoes the same below the baseline.line-gap-overridesets extra leading. Most modern web fonts use 0%, and matching it removes one more source of difference.
The override percentages apply after size-adjust, so derive the ascent and descent values by dividing the web font's metrics by the size adjustment, as shown below.
Calculating the Values
Every value comes from two sets of numbers: the web font's metrics, read from its hhea and OS/2 tables, and the fallback font's average character width.
Average width is the part that needs care. A plain mean over all glyphs weights rarely used characters equally with "e" and "t", so tools weight each glyph by how often it appears in the site's language. For English body text the frequency-weighted value lands within one or two percent of the real rendered width; for German, French or code-heavy pages, use the matching frequency table or measure against real content.
Generating Fallbacks in the Build
Calculating by hand works once, but the values must change whenever the font file or weight changes. Generate them instead.
- fontaine (from the UnJS project) is a Vite and webpack plugin that reads the
@font-facerules in your CSS, calculates overrides for a list of fallbacks and injects the extra faces. It works with Astro, Nuxt and any Vite-based build. - Capsize exposes the metrics of common fonts as JSON and a
createFontStackhelper that outputs the fallback@font-faceCSS; it suits Eleventy and Hugo pipelines where a small Node script writes a CSS partial. - next/font does the same automatically in Next.js, including for static export.
A minimal fontaine setup in Astro:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { FontaineTransform } from 'fontaine';
export default defineConfig({
vite: {
plugins: [
FontaineTransform.vite({
fallbacks: ['Arial', 'Helvetica Neue', 'Liberation Sans'],
resolvePath: (id) => new URL(`./public${id}`, import.meta.url),
}),
],
},
});
After a build, check the emitted CSS: each web font family should have a companion Inter fallback face with the four descriptors, and the font-family stacks should list it second.
Tuning Per Platform
Arial is present on Windows and macOS but absent on most Linux desktops and on Android, where Roboto or Liberation Sans take its place. Each has slightly different widths, so one set of values fits one platform best. Where the difference matters, declare separate fallback faces with values tuned for each local font and list them all:
body {
font-family: 'Inter', 'Inter Fallback Arial', 'Inter Fallback Roboto', sans-serif;
}
The browser picks the first face whose local() source exists. Test each by forcing the web font to fail — block the font URL in DevTools' network request blocking — and comparing paragraph heights against a normal load.
Verifying the Match
Numbers from a tool are a starting point, not proof. Two quick checks confirm the fallback really occupies the same space:
- Block the font and compare heights. Load a long article normally and note the height of the main content element in DevTools. Block the WOFF2 URL with network request blocking, reload, and compare. A good match is within one line over several thousand words.
- Record a swap on a slow connection. Throttle to "Slow 4G", open the Performance panel and record a load. The Layout Shift track should show no entries at the moment the font arrives; any that remain are attributed to the elements that moved, which points to the face or weight that still needs tuning.
Repeat both checks after any font upgrade, because a new release of the same family can change its metrics.
Measured Impact
On a 900-page documentation site using Inter with font-display: swap, font swap accounted for 71% of attributed layout shift. Adding fontaine-generated Arial and Roboto fallbacks took about an hour, added 480 bytes of CSS and no requests, and moved the docs template from 0.11 to 0.02 CLS at the 75th percentile on mobile. The number of URLs in Search Console's "CLS issue: more than 0.1" group fell from 610 to zero within the 28-day window.
Pitfalls & Rollback
- Matching only width.
size-adjustalone fixes wrapping, but line heights still change; always set the vertical overrides too. - Forgetting bold and italic. Each weight and style used above the fold needs its own fallback face, because bold glyphs are wider.
- Monospace code blocks. Code fonts need their own fallback matched against Courier New or Menlo, or code samples jump on swap.
- Browser support. Safari added
size-adjustin 17; older versions ignore it and simply show the unmatched fallback, which is no worse than before. - Rollback: remove the fallback faces and the extra family name from the font stack.
Conclusion
A web font swap shifts layout because the fallback font takes a different amount of space. size-adjust fixes line wrapping, the three override descriptors fix line height, and together they turn a local system font into a stand-in with the web font's footprint. Generate the values in the build with fontaine or Capsize, add faces for each platform's fallback, and verify by blocking the font file — text should look different, but nothing on the page should move.
FAQ
What does size-adjust do in @font-face?
It scales every glyph of the font face by a percentage, changing the average character width and therefore how many characters fit on a line. On a fallback face it is used to make a local font such as Arial set text at the same width as the web font.
Why do I need ascent-override and descent-override as well?
size-adjust fixes width, but line height is computed from the font's ascent, descent and line gap. If those differ, each line of fallback text is a different height and paragraphs still grow or shrink on swap. The overrides set those metrics explicitly.
How do I calculate the override values?
Read the web font's metrics from its OS/2 and hhea tables with a tool such as fontkit or Capsize, compare the average character width with the local fallback's, and derive the percentages. Tools like fontaine and next/font generate the values automatically at build time.
Which local font should I use as the fallback?
Pick a font installed on nearly every device whose shapes are close to the web font — Arial or Helvetica for most sans-serifs, Georgia or Times New Roman for serifs. List platform alternatives in separate fallback faces so each operating system gets tuned values.
Related
- Parent: Font Loading Strategies for Static Sites — the full font policy.
- Preloading Fonts Without Double Downloads — shortening the time the fallback is shown.
- font-display: optional vs swap — when a swap happens at all.
- Eliminating Layout Shift from Web Fonts — finding font shifts in field data.
- Self-Hosting Google Fonts to Eliminate Layout Shift — getting the files you read metrics from.