CSS font fallback generator

While a web font downloads, the browser draws your text in a fallback font, then swaps the web font in. If the two fonts have different widths and line heights, every line rewraps at that moment and the page moves: layout shift caused by nothing but typography. This tool reads your font's own vertical metrics and advance widths in the browser, measures a local system font the same way, and writes a fallback @font-face rule with size-adjust and the three metric overrides, so the fallback occupies the space the web font will.

Drop the web font (TTF, OTF, WOFF or WOFF2) to build a fallback for.

Its metrics are read in this tab; the file is not uploaded.

Files are read and processed in this browser tab. Nothing is uploaded — the page’s Content-Security-Policy blocks connections to any other origin.

Where each number comes from

Ascent, descent and line gap are read from the font file: the "hhea" table by default, or the OS/2 typo values when the font sets the USE_TYPO_METRICS flag, which is the choice browsers make too. Each is divided by the font's units per em, so 1,974 units on a 2,000-unit em becomes 98.7%.

size-adjust compares average character width. The web font's widths come from its "hmtx" advances, looked up through its character map; the fallback's are measured in this browser with the canvas text API, from the system font it actually resolves. Both are averaged over the same sample text, weighted by how often each character appears, without kerning. The overrides are then divided by size-adjust, because the browser applies them after scaling the fallback.

Nothing is copied from a table of pre-computed values. If this device does not have the fallback font you pick, the tool says so instead of measuring whatever the browser substitutes.

What it can and cannot match

With all four descriptors set, line height and average line length match closely, which is what removes most reflow: paragraphs keep their number of lines and the content below them stays put. The overlay preview shows both fonts in one box so you can see what is left.

Individual words still differ, because no single scale factor can make Arial's letters the width of another design's letters one by one. Text in a script your sample does not cover will be matched less well; paste representative copy into the sample box for a closer fit.

Windows browsers can lay out fonts without USE_TYPO_METRICS using their usWinAscent and usWinDescent values instead of "hhea". When the font's Windows values differ from the ones used here, the tool shows both so you know the match on Windows will be looser.

Using the rule

Paste the generated @font-face next to your web font's own rule and list the fallback family straight after the web font in font-family. The fallback rule uses local() only, so it downloads nothing. Chromium browsers and Firefox support all four descriptors. Safari added size-adjust in version 17; check its current support for the three overrides before relying on them there. A browser that ignores a descriptor shows the fallback without that adjustment, which is what it would have done anyway.

When it does not work

The tool says the fallback font is not installed.

Why: This device has no font by that name, which is common for Georgia and Courier New on Linux. Measuring the substitute the browser picks would give numbers that are wrong for your visitors.

Fix: Generate the rule on a Windows or macOS machine, where all four fonts are present, or pick a fallback this device has.

Text still shifts slightly when the web font loads.

Why: Average widths match but individual words do not, and font-weight or font-style differences between the faces also change widths.

Fix: Generate a separate fallback for each weight you use, and use a sample text that looks like your real copy.

A warning says a metric had the wrong sign and was set to 0%.

Why: The font stores a value with an unexpected sign, for example a positive hhea descender. CSS cannot express a negative override, and an invalid one would void the whole rule.

Fix: Try the other vertical-metrics source; if both are odd, the font's metrics need fixing at the source.

Related

  • Web-font pack

    Turn a font into a deployable web-font pack in your browser: WOFF2 and WOFF files, a correct @font-face rule with unicode-range, a preload snippet and a manifest, all in one ZIP.

    Open: Web-font pack
  • Previewer

    Preview fonts with your own sample text, sizes, weights, colours and variable-font axis sliders. Rendered by the browser's own FontFace API, so it matches what your visitors will see.

    Open: Previewer
  • Inspector

    Read everything inside a font file in your browser: family and PostScript names, version, copyright and licence text, OS/2 embedding permissions, variation axes, colour tables and the full table directory.

    Open: Inspector
  • Font to Base64

    Encode WOFF2, WOFF, TTF or OTF files as Base64 in your browser: raw strings, data URIs with the correct font/woff2, font/woff, font/ttf or font/otf MIME type, and paste-ready @font-face CSS.

    Open: Font to Base64