Web Fonts: @font-face, Formats, unicode-range and Multiple Styles
Loading your own fonts with @font-face: src with url(), local(), format() and tech(), WOFF2, building a family from several faces, how the browser picks a face by style and weight, unicode-range subsets, cross-origin rules and self-hosting.
kvi5hnuCode Sprout team member7 min readOn this page
Font stacks (article 82) can only use fonts the visitor already has. To use a specific typeface everywhere, you supply the font file yourself with an @font-face rule. It doesn't style anything on its own: it defines a font family name and tells the browser where to get it. You then use that name in font-family as usual.
@font-face {
font-family: "Lora";
src: url("/fonts/lora-regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
body { font-family: "Lora", Georgia, serif; }
The browser downloads the file only when some text on the page actually needs that face.
The src descriptor
src is a comma-separated list of sources, tried in order until one works:
src: local("Lora Regular"),
url("/fonts/lora.woff2") format("woff2") tech(variations),
url("/fonts/lora.woff") format("woff");
| Part | Meaning |
|---|---|
url(…) | a font file to download |
local("Full Name") | a font installed on the device, by its full or PostScript name |
format(…) | the file format, so the browser can skip formats it can't read without downloading them |
tech(…) | font technologies the file needs, like variations, color-COLRv1 or palettes |
Formats:
| Format | Use |
|---|---|
WOFF2 (format(woff2)) | the one to use: compressed, and supported in every browser |
WOFF (format(woff)) | the older compressed format; only needed for very old browsers |
TrueType, OpenType (truetype, opentype) | uncompressed desktop files; larger downloads |
| EOT, SVG fonts | obsolete |
Today a single WOFF2 source is enough. format() keywords can be unquoted (format(woff2)) in current browsers, and invalid sources are skipped instead of invalidating the whole list in Chrome and Firefox.
local() saves a download when the font is installed, but some browsers only allow it for fonts that come with the operating system, since probing for installed fonts can be used to fingerprint users.
Building a family from several faces
A typeface usually comes as several files: regular, italic, bold, bold italic. Give them all the same font-family name, and describe each with font-weight and font-style:

@font-face { font-family: "Lora"; src: url("lora-regular.woff2") format(woff2); font-weight: 400; font-style: normal; }
@font-face { font-family: "Lora"; src: url("lora-italic.woff2") format(woff2); font-weight: 400; font-style: italic; }
@font-face { font-family: "Lora"; src: url("lora-bold.woff2") format(woff2); font-weight: 700; font-style: normal; }
@font-face { font-family: "Lora"; src: url("lora-bold-italic.woff2") format(woff2); font-weight: 700; font-style: italic; }
Now <strong> and <em> use the real bold and italic designs. A common mistake is giving each file its own family name ("Lora Bold"), which forces you to change font-family for bold text, and lets the browser synthesize a fake bold on top when font-weight: bold also applies (article 85).
The descriptors in @font-face don't style text; they say what the file contains, so the browser can match requests against them:
| Descriptor | Example |
|---|---|
font-weight | 400, or a range for variable fonts: 100 900 |
font-style | normal, italic, oblique, or oblique 0deg 12deg |
font-stretch (also font-width in Safari) | 100%, or a range 75% 125% |
unicode-range | which characters the file covers |
font-display | what to show while it loads (article 84) |
font-feature-settings, font-variation-settings | defaults for this face |
How the browser picks a face
When text asks for a weight that no face has exactly, the browser picks the nearest by a fixed rule:
- Asking for more than 500: the nearest heavier face first, then lighter.
- Asking for less than 400: the nearest lighter face first, then heavier.
- Asking for 400 to 500: weights up to 500 first, then lighter, then heavier.
Tested in Chrome, with faces at 400 and 700: font-weight: 600 used the 700 face, and 300 used the 400 face. With faces covering the ranges 100 500 and 600 900, font-weight: 550 used the 600 900 face. Style is matched before weight: italic text uses an italic face of any weight before an upright one. Tested in Chrome: with an upright 700 face and an italic 400 face, bold italic text used the italic 400 face.
unicode-range: subsets
unicode-range tells the browser which characters a file covers, so it can split a large font into subsets and download only the ones the page needs:
@font-face {
font-family: "Noto Sans";
src: url("noto-latin.woff2") format(woff2);
unicode-range: U+0000-007F, U+00A0-00FF, U+2010-2027; /* ASCII, Latin-1 and common punctuation */
}
@font-face {
font-family: "Noto Sans";
src: url("noto-cyrillic.woff2") format(woff2);
unicode-range: U+0400-045F, U+0490-0491;
}
An English page downloads only the Latin file; a page with Russian text downloads both. Ranges are written U+0400-045F, single code points U+20AC, and wildcards U+4??.
unicode-range can also mix fonts: a different typeface for digits, or for the ampersand. When the ranges of faces in a family overlap, the face defined later wins for those characters.
/* two local fonts stand in for web font files, so no download is needed */
@font-face { font-family: "Mix"; src: local("Georgia"), local("Times New Roman"); }
@font-face { font-family: "Mix"; src: local("Courier New"), local("Courier"); unicode-range: U+0030-0039; }
@font-face { font-family: "Pair"; src: local("Georgia"), local("Times New Roman"); font-weight: 400; }
@font-face { font-family: "Pair"; src: local("Courier New Bold"), local("Courier New"), local("Courier"); font-weight: 700; }
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.mix, .pair { font-size: 1.3rem; margin: 0.5rem 0 0.2rem; }
.mix { font-family: "Mix", serif; }
.pair { font-family: "Pair", serif; }
.note { margin: 0 0 0.8rem; color: #555; }
The demo uses local() fonts so it works without downloads; on a system without Georgia and Courier New, the fallbacks apply. With real files the rules look the same, with url() instead.

The browser picks a face per character: in the third panel the two @font-face rules share one family name, and each digit falls in the range of the Courier New face while everything else falls in the Georgia face's range.
Cross-origin fonts and hosting
Fonts loaded from another origin need a CORS header, Access-Control-Allow-Origin, or the browser refuses to use them. Font services send it; if you host fonts on a separate CDN domain, configure it there.
Self-hosting fonts on your own domain is usually best today:
- No connection to a third-party server, which is faster since browsers no longer share caches between sites, and avoids sending visitors' IP addresses elsewhere, which matters under privacy laws.
- You control the subsets,
font-displayand caching.
Check the font's license: many allow web use only under certain terms, and some require a paid web license.
What's current
- WOFF2 works everywhere; unquoted
format()keywords andtech()in all browsers. - Variable fonts with weight ranges in
@font-face(article 87) work everywhere. font-feature-settingsas a descriptor: Chrome 140, Firefox, Safari;font-variation-settingsdescriptor: Chrome 140 and Firefox.- Fallback metric overrides (
size-adjust,ascent-override) are covered in article 84.
Common questions
Do I still need WOFF and TTF files? No. WOFF2 alone is supported in every current browser.
Why is my bold text blurry or too heavy? The browser is synthesizing bold because no face with that weight exists in the family, often because the bold file was given a different family name.
Does @font-face download the font immediately?
No. Only when text that uses that face is rendered, or when you preload it (article 84).
Why doesn't my font load from another domain?
The server must send Access-Control-Allow-Origin for font files.
Summary
@font-facedefines a family name and its source; use the name infont-family.srclistsurl()andlocal()sources withformat()andtech()hints; WOFF2 is all you need.- Give all faces of a typeface the same family name, with
font-weightandfont-styledescribing each. - The browser matches style first, then the nearest weight by a fixed rule.
unicode-rangesplits fonts into subsets that download only when needed, and can mix faces.- Cross-origin fonts need CORS; self-hosting is usually fastest and most private.
Practice questions
Write @font-face rules for a family "Atlas" with a regular file and a bold file, both WOFF2.
Answer
@font-face { font-family: "Atlas"; src: url("atlas-regular.woff2") format(woff2); font-weight: 400; font-style: normal; }
@font-face { font-family: "Atlas"; src: url("atlas-bold.woff2") format(woff2); font-weight: 700; font-style: normal; }
A family has faces at 300 and 700. Which face is used for font-weight: 400, and which for font-weight: 500?
Answer
For 400: weights from 400 to 500 are checked first, and there are none, so the nearest lighter face, 300, is used. For 500: the same, so 300 again. Only requests above 500 prefer heavier faces first.
What does this @font-face rule do on a page with only English text?
@font-face {
font-family: "Site";
src: url("site-greek.woff2") format(woff2);
unicode-range: U+0370-03FF;
}
Answer
Nothing is downloaded: the file only covers Greek characters, and the browser fetches it only if the page has text in that range that uses the "Site" family.
Why is font-family: "Lora Bold" for bold text worse than one family with several faces?
Answer
Every bold element needs its own font-family, and if font-weight: bold also applies, the browser may synthesize extra boldness on top of the bold file. With one family, font-weight picks the right file automatically.
Previous: Font Families: Generic Families, Font Stacks and System Fonts
Next: Font Loading and Performance: font-display, Preloading and Fallback Metrics

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.