What a web font is and how a browser gets one

A web font is a font file that your website sends to the visitor's browser. It means the text looks the way you chose, even if the visitor's device has never had that font installed.1
Without one, the browser uses whatever fonts the device already has. Those are system fonts, and [page:system-fonts-and-font-stacks] covers it.
The trip from file to screen
- The CSS names the font. A rule called
@font-facegives the font a name and points to the file.1 - Some text asks for it. Your CSS uses that name in a
font-familysetting on headings, body text or both. - The browser fetches the file. It only does this when something on the page really uses the font. Writing the rule alone doesn't trigger a download.2
- The browser draws the text. Until the file arrives, it shows either nothing or a stand-in font. [page:font-display-and-flash-of-text] explains that wait.
Words you'll see
- Font file. One file on your server. A single file holds one style, such as bold or italic, unless it's a variable font.2
- Font family. A named group of styles, such as light, regular and bold. Many people call these "fonts", but strictly they're font families.2
- Fallback font. The font the browser uses while the web font is missing, or if it never arrives.
- Generic family. A built-in name such as
seriforsans-serif. It's the last safety net in your list.
How the browser picks a font
Your font-family setting is a list, and the order matters. The browser takes the first font in the list that's installed or that it can download through @font-face.3
Always end the list with a generic family. Fonts can be missing, so there's no guarantee any given one is available.3 If the web font can't load, the generic family gives you a sensible fallback.1
What goes wrong, and where to read next
- The font isn't yours to use freely. Fonts generally come with restrictions, such as payment or credit to the maker.1 See [page:font-licences-in-plain-words].
- The text jumps when the file arrives. Layout shifts happen when a web font and its fallback take up different amounts of space.2 See [page:font-display-and-flash-of-text].
- The file is the wrong type. Browsers read a few formats, and one is the sensible default now. See [page:web-font-file-formats].
- Too many files. Each style you add is another download. See [page:how-many-fonts-are-too-many].
- Where the file lives. It can sit on your own hosting or come from a font service. See [page:self-hosting-or-font-service].
What you actually need to do
The job is short. Four steps:
- Pick a font you're allowed to use on a website.
- Get it in a web-ready format.
- Point
@font-faceat the file, or paste the code a font service gives you. - Use the font's name in
font-family, followed by a generic family.
That's it. Everything else on this site is about doing those four steps with fewer files, fewer surprises and fewer visible jumps.
Cited material
- Web fonts - Learn web development, MDN Web Docs (Mozilla)
- Best practices for fonts, web.dev (Google)
- font-family - CSS, MDN Web Docs (Mozilla)