Web fonts are small compared to images, but they sit in the critical path. The browser can't draw text in a custom font until the file arrives, and it does not even request the file until it has parsed the CSS and found text that uses it. A heavy font file, a slow request or a bad loading setting shows up as invisible text, a late font swap that moves the layout, or both.
Three changes fix most of this: serve the font as WOFF2, subset it so it only contains the characters you use, and set font-display so text never waits for the file. This guide covers those three in order, then adds preloading and a metric-matched fallback font to stop the layout from jumping.
How fonts affect page speed
Fonts touch two Core Web Vitals. When the largest element on the page is a heading or paragraph, the font loading time delays Largest Contentful Paint. When the fallback font and the web font have different dimensions, the swap moves text around and adds to Cumulative Layout Shift. If your largest element is an image instead, how heavy images impact Core Web Vitals (LCP) and how to fix it covers that side.
| Term | What the visitor sees | Cause |
|---|---|---|
| FOIT (flash of invisible text) | Blank space where text should be, until the font arrives. | The font is in its block period. |
| FOUT (flash of unstyled text) | Text appears in a fallback font, then changes to the web font. | The font is in its swap period. |
| Layout shift | Text and elements jump when the font changes. | The fallback and web fonts take up different amounts of space. |
Step 1: Serve WOFF2
WOFF2 wraps a font in Brotli compression, which makes it roughly 25 to 30 percent smaller than WOFF. All current browsers support it, so one WOFF2 file is enough. TTF and OTF files are uncompressed, and older formats such as EOT and SVG fonts are obsolete.
| Format | Compression | Browser support | Use it? |
|---|---|---|---|
| TTF / OTF | None | Everywhere | As a source file only. |
| WOFF | zlib | Everywhere, including very old browsers | Only if you must support legacy browsers. |
| WOFF2 | Brotli, about 25 to 30% smaller than WOFF | All current browsers | Yes. Serve this one. |
@font-face {
font-family: "BrandSans";
src: url("/fonts/brandsans-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
The format("woff2") hint lets a browser skip a file it cannot read without downloading it. If you do need a legacy fallback, add a second url() with format("woff") after the WOFF2 one. Browsers use the first format they support.
Step 2: Subset the font
A typical font file holds thousands of glyphs for dozens of languages and rarely used symbols. A site written in English needs a few hundred of them. Subsetting removes the rest, and the file shrinks accordingly. It also converts the format in the same step.
Install the tool
The free fonttools package includes pyftsubset. WOFF2 output needs the brotli module as well.
pip install fonttools brotli
Create a Latin subset
The command below keeps basic Latin, Latin-1 accented letters, common punctuation and a few symbols such as the euro sign. The range is modeled on the one Google Fonts uses for its Latin subset.
pyftsubset BrandSans-Regular.ttf \
--unicodes="U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD" \
--layout-features="kern,liga,calt,ccmp,locl,mark,mkmk" \
--flavor=woff2 \
--output-file=brandsans-regular-latin.woff2
--unicodeslists the code points to keep. Anything not listed is removed.--layout-featureskeeps only the OpenType features you name, such as kerning (kern) and ligatures (liga). Features you do not list are dropped, which saves more space.--flavor=woff2writes the result as WOFF2.
If your CSS uses features such as tabular numbers (font-variant-numeric: tabular-nums) or small caps, add their feature tags to the list. The += form appends to the default list:
--layout-features+=tnum,smcp
Other subsetting options
| Goal | Option | Notes |
|---|---|---|
| Only the characters in a logo or headline | --text="Your Text" or --text-file=headline.txt |
The smallest possible file. Any other character falls back to another font. |
| Accented and extended Latin letters | A second subset with --unicodes="U+0100-02AF,U+1E00-1EFF,U+2C60-2C7F,U+A720-A7FF" |
Covers the Latin Extended blocks. Used for languages like Polish, Czech and Vietnamese. |
| Other scripts, such as Bengali | A separate subset with that script's range, for example U+0980-09FF |
The font must contain those glyphs in the first place. |
| Convert only, keep everything | --unicodes='*' --glyphs='*' --layout-features='*' |
Useful when you only want the WOFF2 conversion. |
What happens to missing characters
A character that is not in your subset is drawn by the next font in your font-family list. If none has it, the browser shows an empty box. After subsetting, load a page that uses every language, symbol and punctuation mark on your site and look for characters in the wrong font. Curly quotes and dashes live in the U+2000-206F block, so keep it in the range.
Step 3: Split by unicode-range
You can ship several subsets under one family name. With unicode-range, the browser downloads a file only when the page contains characters from that range. Most visitors on an English site fetch the Latin file and never touch the Latin Extended one.
@font-face {
font-family: "BrandSans";
src: url("/fonts/brandsans-regular-latin.woff2") format("woff2");
font-weight: 400;
font-display: swap;
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: "BrandSans";
src: url("/fonts/brandsans-regular-latin-ext.woff2") format("woff2");
font-weight: 400;
font-display: swap;
unicode-range: U+0100-02AF, U+1E00-1EFF, U+2C60-2C7F, U+A720-A7FF;
}
Each range in the CSS must match what you put in that file with --unicodes. A character in a declared range makes the browser download the file, even if the file lacks the glyph.
Step 4: Set font-display
The font-display descriptor tells the browser what to show while the font loads. A font goes through up to three stages: a block period where text is invisible, a swap period where a fallback shows and the web font replaces it when it arrives, and then a failure period where the fallback stays. It has been available across browsers since January 2020.
| Value | Block period | Swap period | Best for |
|---|---|---|---|
auto |
Browser decides, usually like block |
Browser decides | Nothing. Set a value yourself. |
block |
Short (about 3 seconds is the usual recommendation) | Unlimited | Icon fonts and logos, where a fallback letter would be wrong. |
swap |
Extremely short | Unlimited | Body text, where reading should start at once. The late swap can shift the layout. |
fallback |
Extremely short | Short (about 3 seconds) | Body text on slow connections. A font that arrives too late is not swapped in. |
optional |
Extremely short | None | Non-essential fonts and the lowest layout shift. The font may not show on the first visit. |
The exact length of the "short" and "extremely short" periods is up to the browser. For most sites, swap is the safe default, and optional suits designs where a fallback font on the first visit is acceptable. With optional, the browser may also treat the download as low priority, and the font usually appears from the second page view onward.
&display=swap to the stylesheet URL. You can only set one value for the whole request, so every font in it gets the same behavior.
Step 5: Preload the critical font
Without a hint, the browser finds a font late: it must download the HTML, download and parse the CSS, build the page and see text that needs the font. A preload tells it about the file at the start.
<link rel="preload" href="/fonts/brandsans-regular-latin.woff2" as="font" type="font/woff2" crossorigin>
crossoriginis required, even when the font is on your own domain. Browsers fetch fonts in anonymous CORS mode, so a preload without the attribute does not match the later font request, and the file downloads twice.type="font/woff2"lets browsers that cannot read WOFF2 skip the request.- The
hrefmust match the URL in your@font-faceexactly. - Preload one or two files, the ones used in the first screen of text. Preloading every weight and subset competes with other resources and wastes bandwidth.
Give font files a long cache lifetime and put a version in the file name, so visitors do not download them again:
Cache-Control: public, max-age=31536000, immutable
Step 6: Stop the layout shift with a matched fallback
With swap, the page first renders in the fallback font and moves when the web font arrives. The move is small when both fonts have similar proportions and large when they do not. You can close the gap by adjusting a local fallback font to match the web font's dimensions.
/* A local font adjusted to match the web font. The values are examples. */
@font-face {
font-family: "BrandSans Fallback";
src: local("Arial");
size-adjust: 105%;
ascent-override: 92%;
descent-override: 24%;
line-gap-override: 0%;
}
body {
font-family: "BrandSans", "BrandSans Fallback", sans-serif;
}
| Descriptor | What it adjusts | Support |
|---|---|---|
size-adjust |
Scales glyphs so text takes up the same width. | Chrome, Edge and Firefox 92 and later, Safari 17 and later |
ascent-override, descent-override |
Sets the space above and below the baseline, which controls line height. | Chrome and Edge 87 and later, Firefox 89 and later. Safari support is limited, so check current compatibility. |
line-gap-override |
Sets the extra space between lines. | Same as the overrides above |
Browsers without support ignore the descriptors, so the worst case is the same shift you had before.
Putting it together
Here is the full setup for a self-hosted body font with two subsets. Adjust the file names to your own.
<head>
<link rel="preload" href="/fonts/brandsans-regular-latin.woff2" as="font" type="font/woff2" crossorigin>
<link rel="stylesheet" href="/css/fonts.css">
</head>
/* fonts.css */
@font-face {
font-family: "BrandSans";
src: url("/fonts/brandsans-regular-latin.woff2") format("woff2");
font-weight: 400;
font-display: swap;
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: "BrandSans";
src: url("/fonts/brandsans-regular-latin-ext.woff2") format("woff2");
font-weight: 400;
font-display: swap;
unicode-range: U+0100-02AF, U+1E00-1EFF, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: "BrandSans Fallback";
src: local("Arial");
size-adjust: 105%;
ascent-override: 92%;
descent-override: 24%;
line-gap-override: 0%;
}
body {
font-family: "BrandSans", "BrandSans Fallback", sans-serif;
}
Self-hosting or Google Fonts
| Self-hosted | Google Fonts | |
|---|---|---|
| Setup | You subset, convert and upload the files. | One line of CSS. |
| WOFF2 and unicode-range subsets | You create them. | Served automatically. |
| Extra connections | None if the files are on your domain. | A stylesheet request, then font files from a second domain. |
| Preloading and cache headers | Full control. | Limited. You cannot preload the files reliably. |
font-display per font |
Yes, in each @font-face. |
One value per request. |
| Shared cache with other sites | Not applicable. | No longer a benefit, because modern browsers cache separately for each site. |
If you stay on Google Fonts, add display=swap, request only the weights and styles you use, and add &text= for fonts that appear in a short fixed string such as a logo.
Access-Control-Allow-Origin header, or the browser blocks the font. Blogger also reads the theme as XML, so a preload tag needs quoted attribute values and a closing slash:
<link rel='preload' href='https://cdn.example.com/fonts/brandsans-regular-latin.woff2' as='font' type='font/woff2' crossorigin='anonymous'/>
Put the @font-face rules inside the theme's <b:skin> CSS block. If the Edit HTML screen is new to you, how to install a Blogger template properly explains how the Theme screen works.
Measure the result
- Open the page in Chrome, press F12, open the Network tab and select the Font filter.
- Tick Disable cache, set throttling to Slow 4G and reload.
- Check the list. Only the files the page needs should appear, and each should be requested once. A preloaded file that shows up twice points to a missing
crossorigin. - Compare the Size column before and after your changes. It shows the transferred size above the uncompressed one.
- Open the Rendering panel from the DevTools menu and tick Layout Shift Regions. Reload and watch for blue flashes around text when the font swaps.
- Run Lighthouse or PageSpeed Insights before and after, and compare LCP and CLS.
Troubleshooting
The font downloads twice
The preload is missing crossorigin, or its href differs from the URL in @font-face, even by a query string. Make both identical and keep the attribute.
Console warning: preloaded but not used
The browser preloaded a file and the page did not use it in the next few seconds. The usual causes are a crossorigin mismatch, a font family name that does not match, or a font used only on pages other than the current one. Preload only fonts that appear above the fold.
Failed to decode downloaded font
Failed to decode downloaded font, usually followed by OTS parsing error.
The file is corrupted, was converted incorrectly or is not really WOFF2, for example a renamed TTF. Convert it again from the original source. If the message is unclear, how to read error messages like a developer shows how to find the useful line.
The font is blocked by CORS
The font is on a different domain and the server does not send Access-Control-Allow-Origin. Add the header on the server that hosts the files.
Some characters show in the wrong font or as boxes
Those characters are not in your subset. Add their code points to --unicodes, and to the unicode-range descriptor if you split the files.
A subset file downloads when I expected it not to
The page contains at least one character inside that range. The Latin range includes punctuation such as curly quotes and dashes, so a Latin file is requested on almost every page. A Latin Extended file should load only on pages that use those letters.
Text is invisible for a long time
The @font-face rule has no font-display, so the browser's default block behavior applies. Add font-display: swap or optional.
FAQs
Do I still need WOFF as a fallback for WOFF2?
For almost all sites, no. Every current browser supports WOFF2. A WOFF fallback only helps visitors on very old browsers, and modern browsers never download it, but it adds files for you to produce and maintain.
Which font-display value should I use?
Use swap for body text on most sites, so reading starts immediately. Use optional if you want to avoid layout shift and accept the fallback font on the first visit. Use block only for icon fonts. Pair swap with a metric-matched fallback to keep the shift small.
Will subsetting break accented letters or special characters?
Only the characters you leave out. The Latin range in this guide keeps accented letters used in Western European languages, punctuation and common symbols. Test a page that uses every special character on your site, and add the code points of anything that falls back to another font.
Should I preload every font file?
No. Preload one or two files used in the first screen of text, usually the regular weight of the body or heading font. Each preload competes with CSS, images and scripts for bandwidth, and an unused preload is wasted.
Is a variable font better than several static files?
It depends on how many styles you use. A variable file is larger than a single static weight, but it can replace many files, so it is often smaller overall once you use three or more weights or styles. For one or two weights, subset static files and compare the sizes.
Conclusion
Serve WOFF2, subset each font to the characters you actually use, and set font-display on every @font-face. Preload the one or two files that appear in the first screen of text, and match the fallback font's size to the web font to reduce the shift when it swaps. Then measure in DevTools, since the file sizes, the number of requests and the layout shifts show whether each change helped.