The short answer
Web fonts are font files a page downloads so text can appear in a typeface the visitor's device does not have. Text flashes or jumps because the fallback font and the web font differ while the file loads. Fix it with the font-display setting, WOFF2 files, subsetting, preloading only the fonts used above the fold, and a well-matched fallback.
What web fonts are
Web fonts are font files that a page downloads so text can appear in a typeface the visitor's device does not already have. Without them, a page can use only the fonts installed on each device, which differ between phones, laptops and operating systems. A web font lets you choose one typeface and have it appear the same way everywhere.
In the page's CSS, a rule called @font-face tells the browser the name you are giving the font and where to find the file. The browser then downloads the file when text on the page needs it. That download is the source of every problem in this guide: the page cannot show the final text in the right font until the file arrives, so the browser has to decide what to show in the meantime.
The format matters less than it used to. WOFF2 is supported by current browsers, so unless you must serve very old ones, use WOFF2 and skip the older formats. If you list more than one format, put WOFF2 first, because the browser picks the first one it supports.
What the browser does while a font loads
The sequence is the same on almost every page.
- The browser receives the HTML and starts reading it.
- It finds the CSS and works out which fonts the visible text needs.
- It requests those font files. They are not discovered until the CSS has been read, which is why they can arrive late.
- While waiting, it must either hide the text, show it in a fallback font, or wait for a short time and then pick one.
- When the file arrives, it may swap the text into the web font.
Two visible problems follow. In the first, text is invisible for a moment and then appears. In the second, text appears in a plain fallback font and then changes to the web font. Designers sometimes call these a flash of invisible text and a flash of unstyled text. Both are normal behaviour, controlled by one CSS setting.
The third problem is the jump. Even invisible text takes up space, laid out using the fallback font. When the real font arrives and has different letter widths or line heights, the text block resizes and everything below it moves. That movement is a layout shift, and it counts against your Cumulative Layout Shift score.
Choosing a font-display value
The font-display descriptor in the @font-face rule tells the browser how to behave while the file loads. Web.dev and MDN describe the main values like this; check their current documentation for exact timings.
| Value | What the visitor sees | Good for | Risk |
|---|---|---|---|
| block | Text can stay invisible for a few seconds, then appears in the web font | Cases where the wrong font would look broken, such as a logo made of text | Slow connections see nothing for a while |
| swap | Text appears at once in a fallback, then changes when the font arrives | Headings and brand elements where the typeface matters | The change late in loading can shift the layout |
| fallback | A very short invisible period, then fallback text, with a limited window to swap | Body text where a quick, stable page matters most | Some visits end up with the fallback |
| optional | A very short invisible period, then the fallback is used if the font is late | Body text when speed and stability matter more than the exact typeface | Some first visits never show the web font, though later visits usually do |
Web.dev calls optional the most performance-friendly choice, because there is no swap and so no layout shift from the swap itself. A common approach is to use swap for a distinctive heading font and optional or fallback for body text. Sources differ on whether to preload a font that uses optional, so test both on your own pages.
Making the swap hard to notice
Even with a good setting, the change from fallback to web font should not move the layout. The fix is to make the fallback behave like the real font. CSS lets you define an adjusted local font, using descriptors such as size-adjust, ascent-override, descent-override and line-gap-override, so the fallback has nearly the same width and line height as the web font. When the real font arrives, little changes. Free calculators can suggest the values for a given font. Support for these descriptors varies by browser and version, so ask your developer to check MDN's current compatibility tables.
Also finish every font stack with a generic family such as sans-serif or serif, so something sensible shows if every other option fails. Choose a web font with proportions close to the system font where you can; a typeface with unusually wide letters will always jump more.
How to load fonts faster
These steps cut the wait, roughly in order of payoff.
- Download less. Subset the font to the characters you use and serve WOFF2. Subsetting matters most for languages with very large character sets such as Japanese, Chinese and Korean, where a full font can be many megabytes. The unicode-range setting makes the browser fetch a file only when the page contains characters from that range, which also helps sites that offer several scripts, such as Latin and Arabic.
- Load fewer files. Every family, weight and italic is normally a separate file. A variable font packs a range of weights into one file, which can replace several static files, though the single file can be larger, so compare sizes.
- Preload the fonts used in the first screen. A preload link tells the browser to start the download before it finds the font in the CSS. It needs the as attribute set to font, the type set to font/woff2 and the crossorigin attribute, or the browser ignores it. Preload only one or two fonts. Too many preloads compete with more important files.
- Serve the files from your own domain or from a fast host. Self-hosting avoids an extra connection to another company, and some businesses prefer it for privacy reasons. If you serve visitors in regions with strict rules on third-party requests, ask a lawyer.
Fonts are discovered through CSS, so the lazy loading used for images and video does not apply to them. The guide to lazy loading explains what that technique does cover.
How many fonts can a site use?
There is no fixed limit. The practical limit is how many files the page downloads before the visitor sees text, and each one costs time. For most business sites, one or two families, each in two or three weights, is plenty. Treat the file count, not the family count, as the figure to watch.
| What you add | Effect |
|---|---|
| A second family | At least one more file, often several |
| Another weight, such as bold or light | One more file, unless you use a variable font |
| Italic styles | One more file per weight you use in italic |
| Support for another script or language | More files, or a larger subset |
| An icon font | One more file; check whether inline images would be lighter |
Do not load weights that no page uses. If the design needs bold only in two headings, check whether a regular weight there would do. Avoid fake bold, where the browser thickens a font that has no bold file, because it looks worse than the real thing. For a focused page that exists to convert one campaign, be strict: one family and two weights is a good limit, as the guide to landing page versus website explains for such pages.
Licences, briefs and developer handover
A licence for printing or for desktop software is not always a licence for a website. Web use may need its own licence, sometimes based on traffic, and the terms differ between suppliers. Read the licence, and ask the supplier if it is unclear.
Put your font decisions in the website brief for your developer: the typefaces, the weights, the languages and scripts you need, the fallback fonts, and the proof that you hold a web licence. A hosted font service works like an API, a connection to another company's system, so it helps to read what an API is before you depend on one. Decide what visitors should see if that service is slow or unavailable.
How to check fonts on your own site
Open your browser's developer tools and go to the Network tab. Filter by fonts and reload the page. Note how many font files load, how large each is and how late they start. Then use the throttling option to simulate a slow connection, reload and watch the text. If it flashes or jumps, try a different font-display value or adjust the fallback, and test again.
Finish with a speed test of the page. The guide to checking and improving website speed explains the tools and how to read the results. If you want help tuning font loading on an existing site, Liftup Technologies' website development service is one place to start.
