Free, independent guides since 2010

Code

Web fonts: self-hosting, performance and privacy

How to use custom fonts on a website without slowing it down: font formats, self-hosting versus font services, font-display, preloading, subsetting, variable fonts and privacy considerations.

<guide section="Code" type="guide" read="1 min"/>

Typography makes or breaks a design (see typography for the web), but every font file has to be downloaded before text looks right. Done carelessly, fonts slow your site and cause text to jump. Done well, they cost almost nothing. Our older tutorial using fonts in HTML covers the basics.

Self-host your fonts

CSS
@font-face {
  font-family: "Bitter";
  src: url("bitter.woff2") format("woff2");
  font-weight: 100 900;   /* variable font: all weights in one file */
  font-style: normal;
  font-display: swap;
}
body { font-family: "Bitter", Georgia, serif; }
  • Use WOFF2 – the most compressed format, supported everywhere.
  • Serve fonts from your own domain: no extra connection, no data sent to a third party.
  • Check the licence: open-source fonts (for example under the SIL Open Font License) may be self-hosted.

Performance tricks

TechniqueEffect
font-display: swapText shows immediately in a fallback font
Preload the main fontStarts the download early
SubsettingRemove characters you never use (e.g. other alphabets)
Variable fontsOne file for many weights
Matching fallback fontsLess layout shift when the font loads
HTML
<link rel="preload" href="bitter.woff2" as="font" type="font/woff2" crossorigin>

System font stacks

For maximum speed, use the fonts already on the visitor’s device:

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

Frequently asked questions

Is it illegal to use Google Fonts from Google’s servers?

Not illegal in itself, but a German court ruled in 2022 that loading fonts from a third-party server without consent violated a visitor’s privacy. Self-hosting avoids the issue entirely.

How many fonts should a website use?

Usually one or two families, with a few weights. More fonts mean more downloads and a less consistent design.