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
@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
| Technique | Effect |
|---|---|
font-display: swap | Text shows immediately in a fallback font |
| Preload the main font | Starts the download early |
| Subsetting | Remove characters you never use (e.g. other alphabets) |
| Variable fonts | One file for many weights |
| Matching fallback fonts | Less layout shift when the font loads |
<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:
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.