Font Subsetting and Performance
A font file is built to cover far more than any single site needs. A typical text font carries glyphs for Latin, its accented extensions, sometimes Greek and Cyrillic, punctuation, currency symbols, mathematical operators, and the hinting data that tells low-resolution screens how to render each one. A site that only ever displays English text pays the download cost of all of it. Subsetting is the practice of stripping a font down to just the glyphs you actually use, which can cut a file to a fraction of its original size. This page covers how subsetting works, how unicode-range lets the browser skip downloads, the tools that build subsets, and how the whole thing interacts with the flash of invisible or unstyled text during loading.
Why Font Files Are Large
The size of a font scales with the number of glyphs it contains and the amount of hinting and layout data attached to them. A full-featured font supporting Latin, Greek, and Cyrillic with multiple weights can run to hundreds of kilobytes per weight. Most of that is glyphs a given page never renders. An English-only marketing site uses perhaps a hundred or so distinct characters out of the thousands a font may define, which means the overwhelming majority of the download is wasted bytes that still have to travel the network and delay the first paint of text.
Subsetting addresses this directly by producing a new font file that contains only a chosen set of glyphs. Drop every script you do not use, every weight you do not load, and often the result is a file a quarter or less of the original size. The visible text is identical; only the unused glyphs are gone.
Telling the Browser What a File Covers with unicode-range
The Web Fonts reading introduced the unicode-range descriptor on @font-face. It is the mechanism that makes subsetting pay off automatically. The descriptor declares which Unicode code points a particular font file provides, and the browser uses that information to decide whether the file is even worth downloading: if none of the characters on the current page fall within a file's declared range, the browser skips that download entirely.
/* Latin subset: only fetched if the page uses Latin characters */
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-latin.woff2') format('woff2');
font-display: swap;
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F;
}
/* Cyrillic subset: only fetched if the page uses Cyrillic characters */
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-cyrillic.woff2') format('woff2');
font-display: swap;
unicode-range: U+0400-045F, U+0490-0491;
}
This is how large font services split a family into per-script files behind one font name. A page in English requests only the Latin file; a page in Russian requests only the Cyrillic one. The reader never downloads a script they are not reading, and you never have to manage which file loads, because the browser matches code points to ranges on its own. The unicode-range descriptor has universal browser support, so this technique is safe to rely on everywhere.
Static and Dynamic Subsetting
There are two broad approaches to producing subsets. Static subsetting builds the subset files ahead of time as part of your project: you decide which characters or scripts you need, run a tool that outputs the trimmed files, and host them yourself. This gives you complete control over exactly which glyphs ship and works without any third-party dependency at runtime.
Dynamic subsetting generates the subset on demand, usually through a font hosting service. Google Fonts, for example, inspects the text parameter or the characters a page declares and serves a file tailored to them. This is convenient and requires no build step, but it ties your fonts to an external service and gives you less direct control over caching and exactly what is delivered. For a production site you control, static subsetting is generally the more robust choice; for rapid prototyping, dynamic subsetting through a service is faster to set up.
Tools for Building Subsets
Several tools build subset files, and the right one depends on your workflow rather than any single tool being correct. The most common options are:
- glyphhanger scans your actual pages to discover which characters you use, then drives the subsetting for you, which removes the guesswork of listing code points by hand
- fonttools and its pyftsubset command is the underlying Python toolkit that performs the subsetting itself, giving precise control over ranges, features, and output format
- Wakamai Fondue inspects a font and reports exactly what it contains, including its glyphs, features, and axes, which helps you decide what is safe to remove
A common workflow combines them: inspect a font to see what it holds, scan your pages to see what you use, then run the subsetter to produce the trimmed file. None of these is required over the others, and many build pipelines wrap them in higher-level plugins, so choose based on how your project is already structured.
Seeing the Size Impact
The demo below models how a font file shrinks as you remove scripts you do not need. Start from a full multi-script file and toggle off the ranges your site never displays, watching the resulting file size drop. The figures are representative of a typical subset woff2 file rather than any one specific font.
Subsetting, FOIT, and FOUT
Subsetting changes how long the font download takes, which directly affects what the reader sees during loading. There are two failure modes a web font can produce while it loads, and the font-display property covered on the Web Fonts reading decides which one happens.
A flash of invisible text, or FOIT, happens when the browser hides text while waiting for the font, leaving a blank space where words should be. A flash of unstyled text, or FOUT, happens when the browser shows the text immediately in a fallback font and then swaps to the web font once it arrives, causing a visible change. Neither is inherently better; FOIT avoids a visual swap at the cost of hiding content, while FOUT keeps content readable at the cost of a noticeable shift.
Subsetting improves both situations by shrinking the download, which shortens the window during which either flash can occur. A smaller file arrives sooner, so a FOIT period is briefer and a FOUT swap happens faster, closer to the initial paint where it is less jarring. Subsetting does not replace a deliberate font-display choice; it makes whichever choice you make less costly by reducing the time the font spends in flight.
Teaching Video Checklist
When you record your teaching video, make sure your teammates come away understanding these concepts:
- Why a font file is larger than a site needs, and what subsetting removes
-
How
unicode-rangelets the browser skip downloading files whose code points do not appear on the page - The difference between static subsetting that you build ahead of time and dynamic subsetting served by a font service
- What at least one tool does in the subsetting workflow, such as scanning pages for used characters or trimming a file to a range
- The difference between FOIT and FOUT, narrated against a loading font, and how a smaller subset shortens both
- Your own before and after on your portfolio: record the font request in the browser network panel with and without a subset, and show the difference in file size and load time
Start by opening the network panel, filtering to fonts, and reloading with the cache disabled so teammates can see the real request, then compare that request before and after subsetting to make the savings concrete.
Resources
- MDN: unicode-range documents the descriptor and how the browser matches ranges to page content
- glyphhanger scans pages for used characters and drives subsetting
- fonttools pyftsubset is the underlying toolkit that performs the subsetting
- Wakamai Fondue reports exactly what a font file contains so you know what is safe to remove
- web.dev: Reduce web font size covers subsetting, unicode-range, and the performance impact in depth