@font-face Generator
Write production @font-face CSS for your web fonts – every weight
and style, with font-display, variable ranges, optional
unicode-range subsetting and a matching preload hint.
Faces
How to use this tool
- Name the family. This is the name you will use in
font-family, and it does not have to match the file name. - Set the path to wherever the files are served from –
/fonts, a CDN URL, whatever your build produces. - Add one face per file. Regular and bold are filled in as an example; add italic or other weights as needed.
- Tick "Variable" for a variable font and give it a weight range instead of a single weight.
- Copy the CSS into your stylesheet, and the preload tag into
your
<head>.
Why there is only WOFF2 in the output
Because that is all you need. WOFF2 has been supported by every current browser
since about 2016. The familiar four-format stack – EOT, TTF, WOFF, SVG – is
Internet Explorer scaffolding, and browsers take the first format they understand,
so the extra src entries are dead weight in every stylesheet carrying
them.
If your analytics genuinely show old browsers, add a WOFF entry after the WOFF2 one. For most sites that is a line of CSS solving a problem they do not have.
Choosing font-display
- swap – the fallback shows immediately and is replaced when the font arrives. Text is never invisible. The right default for body copy.
- optional – the browser may skip the font entirely on a slow connection. Best when the web font is a nicety rather than the brand.
- fallback – a very short invisible period, then a short swap window. A compromise if the layout shift from swapping bothers you.
- block – hides the text for up to three seconds. Almost always the wrong choice; it is what makes pages appear blank on bad connections.
- auto – leaves it to the browser, which in practice behaves
much like
block.
What unicode-range actually does
It tells the browser which characters a file covers. If nothing on the page uses those characters, the file is never downloaded. That is how a multilingual family can declare a dozen faces and still cost one download on an English page.
It only pays off if your font files are already split along those lines. If you have one file containing every script, declaring a Latin range on it does not make it smaller — the browser still fetches the whole file. Splitting the file is a subsetting job, which this tool does not do.
About the preload tag
The generated tag preloads only the first face. That is deliberate. Preloading every weight is a common and expensive mistake: it makes the browser fetch fonts the page may never use, competing for bandwidth with the CSS that decides whether it will. Preload the one face in your first paint, and let the rest load normally.
The crossorigin attribute is required even for fonts on your own
domain. Fonts are always fetched in anonymous CORS mode, so a preload without it is
treated as a different request and the file is downloaded twice.
Need the files first? TTF to WOFF2 and OTF to WOFF2 convert them in your browser, the font analyzer tells you which weights and axes a file actually contains, and the typography scale generator builds the sizes to set them at.