You picked a font on Google Fonts, pasted the <link> tag, and it works. Now you want the files on your own site — to stop every visitor's browser contacting Google, to drop a connection to another server, or because the page has to work where Google is not reachable.
To self-host a Google Font, download its WOFF2 files, put them in a folder on your site, and declare each one with an @font-face rule in your own CSS — the same rule Google's stylesheet contains, with the file address changed to yours. Keep font-display: swap and the unicode-range lines, preload only the one file the first screen needs (with crossorigin), and serve the font files from the same origin — the same scheme, host and port — as the page. The font licence allows it: most Google Fonts are under the SIL Open Font License.
The 30-second version
| Step | What to do | What goes wrong if you skip it |
|---|---|---|
| Get the files | Copy the WOFF2 files and CSS Google sends to a current browser | Fetched with curl or another non-browser tool, you get TTF: larger, no subsets |
| Declare them | @font-face with src, font-weight, unicode-range, font-display |
Faux bold, or every subset downloaded |
| Choose display | swap for brand text, optional if layout shift matters more |
Invisible text while the font loads |
| Preload one file | <link rel="preload" as="font" type="font/woff2" crossorigin> |
Without crossorigin the file downloads twice |
| Same origin | Serve fonts from the page's own origin | A font on another origin fails without Access-Control-Allow-Origin |
| Rename on change | New file name for a new font version | Visitors keep the old cached file |
What Google's link actually loads
The <link> tag points at a stylesheet, not a font. On 27 November 2026, requesting https://fonts.googleapis.com/css2?family=Inter:wght@400..700&display=swap as Chrome returned seven @font-face rules — Cyrillic, extended Cyrillic, Greek, extended Greek, Vietnamese, extended Latin and Latin — each pointing at one .woff2 file on fonts.gstatic.com and carrying a unicode-range. The Latin file was 48,256 bytes. The same request from curl, with no browser user agent, returned TrueType files instead: one rule per weight, no unicode-range. In that test, the answer depended on who was asking — so a stylesheet copied with a non-browser tool can give you worse files than your browser gets.
unicode-range is what keeps that cheap. The CSS Fonts specification treats it as a hint for whether to download a file at all, and its worked example downloads only the Latin font for Latin text. A page in English fetches one file, not seven.
The Google Fonts CSS API is also where the parameters in that URL come from: wght@400..700 asks for a range of a variable font's weight axis, and display=swap sets font-display.
Is self-hosting faster?
It used to be argued the other way: a visitor might already have the font cached from another site that used Google. That stopped being true in Chrome when Chrome 86 partitioned the HTTP cache — a cached file is now keyed by the top-level site, and the site of the frame that asked, as well as its URL, so a font fetched on one site is fetched again on yours. Chrome's own note says services serving cacheable resources such as fonts across many sites may see more traffic.
What self-hosting removes is the extra connection. In the same 27 November request, Google's stylesheet response carried a Link header telling the browser to preconnect to fonts.gstatic.com, the second server the font files live on. Google's own font best practices put it as "on paper, using a self-hosted font should deliver better performance as it eliminates a third-party connection setup". Measure your own page before and after: the gain depends on the page, so there is no number to promise.
The privacy question
In January 2022 the Regional Court of Munich (case 3 O 17493/20) held that a website passing a visitor's IP address to Google through Google Fonts had no legal justification, since the fonts can be used without contacting Google, and awarded the visitor €100. That is one German court's ruling, not general legal advice — but it is why the question gets asked so often.
Step 1: Get the WOFF2 files
Option A — the files Google already serves. Fetch the stylesheet as a current browser would, download every WOFF2 file it names, and rewrite the addresses to your own folder. This short Node.js script does it:
// get-font.mjs — Node.js 18 or later. Run: node get-font.mjs "Inter:wght@400..700"
import { mkdir, writeFile } from "node:fs/promises";
if (!process.argv[2]) {
console.error('usage: node get-font.mjs "Family:wght@400..700"');
process.exit(1);
}
const family = process.argv[2].replaceAll(" ", "+");
const api = `https://fonts.googleapis.com/css2?family=${family}&display=swap`;
// Google picks the format by browser, so ask as a current one to get WOFF2.
const ua =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0 Safari/537.36";
const res = await fetch(api, { headers: { "User-Agent": ua } });
if (!res.ok) throw new Error(`${res.status} for ${api} — check the family name`);
let css = await res.text();
const urls = [...css.matchAll(/url\((https:[^)]+\.woff2)\)/g)].map((m) => m[1]);
if (urls.length === 0) throw new Error("no WOFF2 files in the stylesheet");
await mkdir("fonts", { recursive: true });
for (const url of urls) {
const name = url.split("/").pop();
const file = await fetch(url);
if (!file.ok) throw new Error(`${file.status} for ${url}`);
const bytes = await file.arrayBuffer();
await writeFile(`fonts/${name}`, Buffer.from(bytes));
// Site in a subfolder (a GitHub Pages project site)? Change "/fonts/" to match.
css = css.replace(url, `/fonts/${name}`);
}
await writeFile("fonts.css", css);It leaves a fonts/ folder and a fonts.css you can link from every page. Run against Open Sans:wght@400..700 on 27 November 2026, it produced ten files, because that family has more subsets. Delete the rules for scripts your site never uses, or keep them — with unicode-range in place, an unused subset is never downloaded.
Option B — the source files. The google/fonts repository holds every family with its licence; the Inter folder, for example, contains Inter[opsz,wght].ttf, the italic, and OFL.txt. Those are TrueType, so convert and subset them yourself with fontTools:
pip install fonttools brotli
fonttools subset "Inter[opsz,wght].ttf" \
--unicodes="U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD" \
--layout-features='*' --flavor=woff2 --output-file=inter-latin.woff2--flavor=woff2 needs the Brotli module, which is why it is installed alongside. --layout-features='*' keeps every OpenType feature, not only the default set fontTools keeps. --text="…" takes literal characters instead of code points, for a logo set in one word.
The licence
The repository README says most fonts in the collection use the SIL Open Font License 1.1, some use Apache 2, and the Ubuntu fonts use the Ubuntu Font License. The OFL allows you to use, embed, modify and redistribute the font; it forbids selling the font by itself. Subsetting counts as modification — the OFL FAQ says so in 2.6 — and the same FAQ says a subset would not normally be allowed to use a Reserved Font Name. Open the font's OFL.txt: if it declares one, the name inside your subset file should change. The licence also asks that copies carry the copyright notice and the licence, so put OFL.txt in your fonts/ folder.
Step 2: Write the @font-face rule
With option A, Google's rules are already written; only the addresses changed. With option B, write one yourself — this one matches the subset made above, and for a variable font one file covers a range of weights:
@font-face {
font-family: "Inter";
font-style: normal;
font-weight: 400 700;
font-display: swap;
src: url("/fonts/inter-latin.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
body {
font-family: "Inter", system-ui, sans-serif;
}font-weight: 400 700. MDN on@font-facedocuments two values as a supported range. Leave it out and, per the CSS Fonts specification, the face is selected as if it were normal weight, and a browser that synthesises bold may fake the bold rather than use the file's own.- WOFF2 only. MDN's
@font-facepage says it is generally best to serve WOFF2: it compresses better than WOFF or OpenType and is well supported in modern browsers. If you list fallbacks,srcis tried in order, so the preferred format goes first. - Paths. A relative address in
url()is resolved against the stylesheet, not the page.fonts/x.woff2inside/css/site.cssmeans/css/fonts/x.woff2. A root-relative path like/fonts/…avoids the question — unless your site is served from a subfolder, as a GitHub Pages project site atuser.github.io/repo/is. There, use/repo/fonts/…, or a path relative to the CSS file.
Step 3: Choose font-display
While a font downloads, the browser has to decide what to show. font-display picks the rule. During a block period, text that uses the font is drawn invisible; during a swap period, it is drawn in a fallback font and replaced when the font arrives.
swap— an extremely small block period, then swap whenever the font arrives. Thedisplay=swapin Google's link sets it, and Google's font guide notes it delays text the least.optional— an extremely small block period and no swap period. The same guide says text render is delayed no more than 100 ms and there are no layout shifts from swapping fonts; on a slow first visit the page may simply keep the fallback.block— a short block period, so text is invisible at first. Rarely what you want for text.
To make the swap less visible, scale the fallback to match. size-adjust multiplies a font's metrics, and MDN's example uses it on a local() fallback for exactly this:
This replaces the body rule from step 2:
@font-face {
font-family: "Inter fallback";
src: local("Arial");
size-adjust: 107%; /* an example: tune it for your two fonts */
}
body {
font-family: "Inter", "Inter fallback", sans-serif;
}The percentage depends on the two fonts; adjust it until a paragraph wraps on the same words in both.
Step 4: Preload the one font the first screen needs
A font is discovered late: the browser reads the HTML, then the CSS, then finds text that needs the font. A preload asks for it early:
<link rel="preload" href="/fonts/inter-latin.woff2" as="font" type="font/woff2" crossorigin>crossorigin is required even though the file is on your own domain. MDN on preload says font preloading needs it, set to match the font request's CORS mode "even when the fetch is not cross-origin" — fonts are always fetched in CORS mode. Google's preload guide is blunter: fonts preloaded without it are fetched twice. type lets a browser that cannot use WOFF2 skip the download. With option A, use the Latin file's name from your fonts.css — the rule commented /* latin */ — so the address matches exactly.
Preload one file, maybe two. The same guide warns that if too many resources are prioritised, effectively none of them are.
Step 5: Keep fonts on the page's own origin
Fonts are not like images. The CSS Fonts specification fetches them in CORS mode, and notes that fonts will typically not load from another origin unless that server sends Access-Control-Allow-Origin. Its examples include one that surprises people: the same domain over http:// from an https:// page is a different origin and fails too.
Google's font files carried access-control-allow-origin: * when measured on 27 November, which is what lets them load on your site. If you move your fonts to a second origin of your own — a shared assets. subdomain, say — that server must send the header. How to set it on Netlify, Vercel, Cloudflare Pages, nginx and Apache is in the custom headers guide. The simpler answer is a fonts/ folder on the same origin as each site.
Step 6: Rename a font file when it changes
A font file rarely changes, so it can be cached for a long time — the Google font file measured above was served with max-age=31536000, one year. Renaming alone does not get you that: the cache lifetime is the Cache-Control header your host sends, set where the host lets you set headers (the custom headers guide has each one). And a long lifetime is only safe if a changed font gets a new address: when you update the font, put a content hash in the name (inter-latin.3f9a1c2b.woff2), and update the CSS and the preload. Why a replaced file under the same name keeps showing is covered in why a site still shows the old version.
What your host does with font files
Any static host serves the files; the details that matter are the Content-Type, the cache lifetime, and whether it lets you add Access-Control-Allow-Origin. Defaults differ from host to host; on hosts that read a _headers file or a config, you can set the last two yourself.
On Drop2Run, .woff2, .woff and .ttf are served as font/woff2, font/woff and font/ttf; .otf is not in the list and goes out as application/octet-stream; convert it to WOFF2 anyway, which is smaller. No Access-Control-Allow-Origin is sent, so fonts work for pages on the same site and not from another origin. On a site without a password, a file named like inter.3f9a1c2b.woff2 — a dot, eight or more hex characters, then the extension — is cached for a year. Any other font name is cached for an hour, including the names option A produces. This is read from apps/router/src/headers.ts at commit 3b3c4d5.
Troubleshooting
Open DevTools, filter the Network panel by Font, and reload.
No font requests at all. The font-family name in your CSS does not match the one in @font-face, or no text on the page uses it. With unicode-range, a subset is also skipped if the page has no characters in its range — that is the feature working.
404 on the font file. The path was resolved against the stylesheet's folder, not the page's. Use a root-relative /fonts/… path — or, if the site lives in a subfolder, a path that includes it or is relative to the CSS file.
Reason: CORS header 'Access-Control-Allow-Origin' missing. Firefox's wording for a font on another origin without the header; other browsers word it differently. Serve the font from the page's own site, or add the header on the font's server. A page opened from your disk hits the same wall for a different reason — see why AI-generated HTML is blank when you open it.
The font downloads twice. One request from the preload, one from the CSS: the preload is missing crossorigin, or its href is not the same address as the src in your CSS.
Bold text looks smeared. The browser synthesised it. Add the weight range to font-weight, or a separate rule for the bold file.
The font changes after a moment and the page jumps. That is swap doing its job. Use optional, tune the fallback with size-adjust, or preload the file.
Still loading from Google. Search your HTML for fonts.googleapis.com — a theme, an embedded widget or a second <link> often keeps one.
When not to do this
- You are prototyping. The Google
<link>is one line and fine for a page that will change tomorrow. - You would rather not use a web font. A system font stack (
system-ui, sans-serif) downloads nothing and never swaps. For body text that is often the better answer. - The font is not openly licensed. Everything above assumes OFL, Apache or the Ubuntu licence. A commercial font's licence decides whether and how you may self-host it — read it before uploading anything.
- You will not maintain it. Google updates its files; yours stay as you downloaded them. For most fonts that is fine. If you need fixes as they ship, keep the link.
Questions
Is it legal to self-host Google Fonts?
For fonts under the SIL Open Font License, yes — it allows embedding and redistribution. The google/fonts README says the Apache 2 and Ubuntu fonts are licensed with permission to redistribute too, subject to their terms. The OFL forbids selling the font by itself, and a subset normally may not keep a Reserved Font Name if the font declares one. Check the licence file in the font's folder.
Do I still need the fonts.googleapis.com link?
No. Remove it, and the preconnect tags for fonts.googleapis.com and fonts.gstatic.com, once your own @font-face rules are in place. Leaving them makes the browser contact Google for nothing.
Should I include WOFF and TTF as fallbacks?
For current browsers, WOFF2 alone is enough; MDN describes it as well supported. Add another format only if you know your visitors use a browser that lacks it, and list WOFF2 first.
Why are there so many files for one font?
Google splits each family by script — Latin, extended Latin, Cyrillic, Greek, Vietnamese and more — and marks each with a unicode-range. The browser downloads only the ones the page's text needs, so keeping them costs nothing.
Does self-hosting make fonts load faster?
It removes a connection to a second server, and since Chrome 86, Chrome no longer shares a cached font across sites, so there is no shared cache to lose there. Whether that is visible depends on your page. Measure it in DevTools.
Can I put the fonts on a CDN or another domain?
Yes, if that server sends Access-Control-Allow-Origin. Without it, the browser refuses to use the font, because fonts are fetched in CORS mode.