Websites & Hosting

Web Fonts: Choosing and Loading Them Well

Pick readable typefaces, serve fewer and smaller files, and stop fonts from hiding text or shifting your layout.

Key takeaways

  • Every font family, weight and style adds a request or extra bytes, so decide what you really use.
  • WOFF2 is the standard compressed format and is supported by current browsers.
  • The font-display descriptor controls whether readers see text while a font loads.
  • Matching fallback font metrics reduces layout shift when the web font swaps in.
  • Check each font's license and the privacy effect of loading it from another company's servers.

To use web fonts well, load as few font files as your design needs, serve them in WOFF2 format, show text immediately in a fallback font while they arrive, and choose faces that stay readable at small sizes. If the design doesn't truly require a custom face, a system font stack costs nothing to download and looks at home on every device.

This guide covers choosing a typeface, deciding where to host it, writing the CSS and preventing the flashes and jumps that annoy readers.

Do you need a web font at all?

A system font stack uses faces already installed:

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

It renders instantly and is usually well tuned for the screen. The trade-off is that your pages look slightly different across platforms. Many sites mix approaches: a custom face for headings and a system stack for body text.

Choose for reading, then for style

Check a candidate with your own content at real sizes.

  • Can you tell apart capital I, lowercase l and the digit 1? An L and I distinction tester is handy for this.
  • Are 0 and O distinct?
  • Is the x-height, the height of lowercase letters like "x," generous enough at body size?
  • Do thin strokes survive on low-resolution screens?
  • Does it include the languages, accented letters, currency signs and figures you need?
  • Are there true bold and italic versions?

Missing styles cause the browser to fake bold or slant, which usually looks smeared. Readability also depends on size, line height and color, covered in color contrast and readability.

Understand formats and file contents

Format or option What it is Advice
WOFF2 Web font container with strong compression Use it
WOFF Older web container Only for very old browsers
TTF / OTF Desktop font files Convert before serving, if licensed
Static fonts One file per weight and style Good for one or two styles
Variable font One file covering a range of weights or widths Good when you use several

A variable font isn't automatically smaller. Compare its size with the static files you'd otherwise send.

Subsetting removes characters you don't need. CSS unicode-range lets you split a family by script, so a browser downloads the Cyrillic or Greek portion only when a page uses it. Be careful not to strip characters that appear in names or user comments.

Decide where to host

Self-hosting puts font files on your own server or CDN. You control caching, there's no extra connection to another domain and visitors' browsers don't contact a third party for type. A hosted font service is quick to set up and may handle subsets for you, but adds a dependency and shares visitor requests with the provider, which has privacy implications in some jurisdictions.

The old argument that a popular font is probably already cached from another site is much weaker now, because major browsers partition their caches by site.

Check the license either way. A desktop license doesn't necessarily allow web embedding, subsetting or format conversion, and some licenses limit traffic or domains.

Write the CSS

@font-face {
  font-family: "ExampleSans";
  src: url("/fonts/examplesans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

body { font-family: "ExampleSans", system-ui, sans-serif; }

The weight range applies to a variable file. For static files, write one @font-face rule per weight with the same family name. Give the files long cache lifetimes and change the filename when the font changes, using the approach in browser caching and Cache-Control headers.

If you serve fonts from a different origin, that server must send suitable CORS headers or the browser will refuse the font.

Control what readers see while loading

Without guidance, a browser may hide text briefly while it waits. font-display sets the policy.

What the main font-display values do
block Hides text for a short period Then shows fallback until loaded Risky on slow links swap Shows fallback right away Swaps whenever the font arrives May shift layout fallback Very brief hidden period Limited time to swap Late fonts are skipped optional Very brief hidden period Browser may keep fallback Most stable for reading block Hides text for a short period Then shows fallback until loaded Risky on slow links swap Shows fallback right away Swaps whenever the font arrives May shift layout fallback Very brief hidden period Limited time to swap Late fonts are skipped optional Very brief hidden period Browser may keep fallback Most stable for reading

For body text, swap or optional are sensible choices. Icon fonts are a special case, since fallback characters make no sense; inline SVG icons are usually better and more accessible.

Preload carefully and match the fallback

Fonts are discovered late, after the CSS is parsed and the browser finds text that needs them. For the one or two files used at the top of the page, a preload hint helps:

<link rel="preload" href="/fonts/examplesans.woff2"
      as="font" type="font/woff2" crossorigin>

The crossorigin attribute is needed even for fonts on your own domain, or the file may be fetched twice. Don't preload everything, because that competes with images and styles that matter more.

When the web font replaces the fallback, lines can rewrap. CSS descriptors such as size-adjust, ascent-override and descent-override let you tune a fallback face to occupy similar space:

@font-face {
  font-family: "ExampleSans Fallback";
  src: local("Arial");
  size-adjust: 104%;
}

The percentage is an example; adjust it by comparing the two fonts, and check browser support for the override descriptors. List the fallback family after your web font in font-family. Reduced shifting improves the layout stability measure described in Core Web Vitals explained.

How a web font reaches the screen
1 HTML arrives A preload hint can start the font early. 2 CSS parsed Font-face rules name available files. 3 Text needs it Browser requests the matching file. 4 Fallback shows Display policy decides what is visible. 5 Font applies Text re-renders in the chosen face. HTML arrives A preload hint can start the font early. 1 CSS parsed Font-face rules name available files. 2 Text needs it Browser requests the matching file. 3 Fallback shows Display policy decides what is visible. 4 Font applies Text re-renders in the chosen face. 5

Plan a small type system

Most sites need less variety than their design files suggest. A workable plan is one family for text and, optionally, one for headings, with these styles:

Role Typical need
Body text Regular weight, plus italic
Emphasis and labels Bold or semibold
Headings One heavier weight, or the body family's bold
Code The system's monospace stack

Each extra weight someone adds "just for this button" is another file. Write the allowed weights into your style guide, and set them as CSS variables so nobody has to guess.

Check what happens in content you don't control. Editors paste italics, writers use bold inside headings and commenters type in other scripts. If a character is missing from your web font, the browser takes it from the next family in the list, so a sensible fallback chain matters. Chinese, Japanese and Korean fonts contain very many characters and can be large, which makes system fonts attractive for those languages unless you can split the files into ranges.

Numbers deserve a look in tables and prices. Some fonts offer tabular figures, which share one width so columns line up, switched on with font-variant-numeric: tabular-nums.

Fix common font problems

  • Font doesn't load at all. Check the network panel for a 404, a wrong path relative to the stylesheet or a blocked cross-origin request.
  • Loaded twice. Usually a preload without crossorigin, or a URL that differs slightly between the hint and the CSS.
  • Bold looks smeared. The bold face isn't declared, so the browser is synthesizing it.
  • Wrong weight appears. The font-weight in @font-face doesn't match what the page asks for.
  • Old font keeps showing. A long cache lifetime with an unchanged filename. Rename the file when it changes.
  • Content security policy errors. The policy's font-src doesn't allow the font's origin.
  • Looks different on one system. Rendering differs between operating systems, so compare there before blaming the file.

If you must convert or subset fonts, keep the originals and the license text with your project files, and note the exact subset you made. Whoever maintains the site later will need to know why a certain character is missing.

Also test printing if people print your pages. Print styles can name a different family, and a pale light weight that looks elegant on a bright screen may come out faint on paper.

Respect readers' settings

Size text in relative units so browser preferences work. Avoid fixed-height containers, because users may apply their own fonts or spacing, and a fallback may be wider than yours. Keep long passages in a regular weight with comfortable line spacing, and use decorative faces only for short headings.

Some readers block web fonts for speed or privacy. Your page should remain legible and usable without them.

Audit what you ship

Open developer tools, filter network requests to fonts and look for files you didn't expect: unused weights left by a theme, the same family loaded by two plugins or a whole icon set for three symbols. Remove them. Then load the page on a throttled connection and watch for invisible text, a jarring swap or buttons that move.

Add a font limit to your performance budget, and revisit it whenever a redesign or new plugin arrives. Render-blocking resources shows how font stylesheets fit with other files that delay the first paint.

Common questions

How many fonts should a site use?

One or two families cover most needs. A third usually adds weight and visual noise without helping anyone read, unless it serves a specific job such as showing code.

Should body text be serif or sans-serif?

Either can read well on modern screens. The particular design, its size, spacing and rendering matter more than the category, so compare candidates with your own paragraphs on a phone and a desktop.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in Websites & Hosting →

Latest news on this topic