At 16 px, “Review the current forecast and export the revised budget.” measures about 445 px in Inter and 415 px in Arial on the test Mac. In a 430 px box, Arial can fit the sentence on one line while Inter wraps it. If the fallback paints first, swapping fonts pushes everything beneath the text down.
Match horizontal advance with size-adjust. Then divide the webfont’s vertical metrics by that same multiplier because CSS scales the overrides along with the glyphs. The result targets the font swap. Other sources of layout shift need separate fixes. CSS Fonts Level 5, metric overrides
Measure the copy and generate the descriptors
Serve the Latin regular font from @fontsource-variable/inter@5.3.0 as /fonts/inter-latin-wght-normal.woff2. The file is in the package's files/ directory. Use the first @font-face from the stylesheet below when running this code. Arial must be installed on the machine that performs the measurement.
Compile this block with tsc --target es2022 --module es2022 metrics.ts, then include metrics.js as a module script. Measure at 100 CSS pixels to derive a ratio independent of the final element size. Give the canvas the same weight, style, and copy as the element.
const copy = "Review the current forecast and export the revised budget."; async function fallbackMetrics() { const webFace = '400 100px "Inter Web"'; const [inter] = await document.fonts.load(webFace, copy); if (!inter) throw new Error("Inter Web must be declared and loaded"); const arial = new FontFace("Arial Measure", 'local("Arial")'); await arial.load(); document.fonts.add(arial); const ctx = document.createElement("canvas").getContext("2d"); if (!ctx) throw new Error("2D canvas is unavailable"); ctx.font = webFace; const primaryWidth = ctx.measureText(copy).width; ctx.font = '400 100px "Arial Measure"'; const fallbackWidth = ctx.measureText(copy).width; if (!(primaryWidth > 0 && fallbackWidth > 0)) throw new Error("Expected positive text advances"); const scale = primaryWidth / fallbackWidth; const percent = (ratio: number) => `${(ratio * 100).toFixed(4)}%`; return { "size-adjust": percent(scale), "ascent-override": percent((1984 / 2048) / scale), "descent-override": percent((494 / 2048) / scale), "line-gap-override": percent(0), }; } console.table(await fallbackMetrics()); export {}; Inter's ascent and descent in this fixture are 1984 and 494 font units on a 2048-unit em, with zero line gap. Use a positive descent in CSS. Advance comes from the rendered sample. To tune body copy, measure a representative set of strings and use the sum of the target advances divided by the sum of the fallback advances. Test longer labels, other weights and every script you ship. Proportional fonts can still wrap individual strings differently. Chrome’s fallback metric derivation · OpenType hhea table
Check wrapping at the swap
The measurements above produce this stylesheet. The plain class gives the control case.
@font-face { font-family: "Inter Web"; src: url("/fonts/inter-latin-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-display: swap; } @font-face { font-family: "Inter Fallback Arial"; src: local("Arial"); font-weight: 400; size-adjust: 107.1289%; ascent-override: 90.4285%; descent-override: 22.5160%; line-gap-override: 0%; } .sample { width: 430px; max-width: 100%; font: 400 16px/24px "Inter Web", "Inter Fallback Arial", Arial, sans-serif; } .sample.plain { font-family: "Inter Web", Arial, sans-serif; } <p class="sample">Review the current forecast and export the revised budget.</p> <p id="after">The next block reveals a change in line count.</p> Without the measurement script on the test page, throttle the font request and disable the browser cache. Record a reload with class="sample plain", then with class="sample". In the Chrome Performance panel, inspect the Layout Shifts track and compare the position of #after before and after the font loads. The control starts at one line and finishes at two at 430 px. With the adjusted face, the sample should start at two lines. Repeat near your actual breakpoints and on platforms where the browser chooses a different fallback. CLS is the largest session window of layout shifts, so inspect the individual shift during the swap as well as the page score. Measure and debug CLS
For a second check, enter the two advances and Inter's vertical metrics in the fallback CSS generator and compare the four descriptors. The maintainers of this article also publish the tool. Webfont fallback CSS generator
AI disclosure. This article was generated with AI.
