Sub topic 3
Google Fonts: what it offers and how it is licensed
This chapter covers what the Google Fonts catalog contains, how its licenses work, and how its delivery service builds the CSS and font files your page receives. It assumes you can write a <link> element, a CSS font-family declaration, and read the Network tab in your browser's developer tools. The next chapters cover fallback stacks and the exact embedding steps. Here the goal is a working model of the service, so that its behavior and its errors make sense.
What Google Fonts is
Google Fonts is two things that share a name:
- A catalog: a directory of more than 1,500 font families, browsable at fonts.google.com, where you filter, preview, and pick styles.
- A delivery service: a public API on
fonts.googleapis.comand a file host onfonts.gstatic.comthat serve CSS and font files to browsers.
You can use the catalog without the delivery service. Every family can be downloaded and served from your own domain, which later chapters cover under self-hosting. You can also use the delivery service without the website, by writing the API URLs by hand. Seeing the two as separate parts explains most of the service's behavior.
You need no account, no API key, and no payment for either part.
Browsing the catalog
The catalog filters are more useful than they first look. The main ones are:
- Category: serif, sans serif, display, handwriting, and monospace. These match the categories from the first chapter of this tutorial.
- Language or script: Latin, Latin Extended, Cyrillic, Greek, Vietnamese, Arabic, Devanagari, and many more. Check this before you commit to a font, because a family that lacks the glyphs for your audience's language will fall back to another font for those characters.
- Number of styles: filters out single-weight families when you need a full range of weights.
- Variable: shows only families that ship as variable fonts, which contain a continuous range of an axis such as weight in a single file.
- Properties: filters such as stroke style or appearance, depending on the current interface.
Each family page shows the available styles, a glyph viewer, the languages supported, and the license. Read the glyph viewer and language list for your content. A font that looks good on "Hamburgefonstiv" may still lack the accented letters or currency symbols your site needs.
Selecting styles
When you click "Get font" and then "Get embed code", the site builds the <link> tags for you from the styles you selected. Every weight and italic you select adds to the request. This is the main place where a page's font payload grows, so choose only what the design uses. The chapter on weights and variable fonts covers this in detail.
How the licensing works
Google Fonts hosts only fonts released under open licenses. Almost all families use one of three:
| License | Typical examples | What it allows | Notable condition |
|---|---|---|---|
| SIL Open Font License 1.1 (OFL) | Inter, Lora, Montserrat, Open Sans | Use, embed, modify, and redistribute, including in commercial work | The font itself may not be sold on its own. Modified versions must not use a Reserved Font Name. |
| Apache License 2.0 | Roboto | Use, modify, and redistribute, including in commercial work | Keep the license notice and state changes when you redistribute. |
| Ubuntu Font License | Ubuntu | Use, modify, and redistribute | Derived versions must be renamed, and the license text must be kept. |
The practical consequences for a web developer are the same across all three:
- Free for commercial use. You can use these fonts on a client's site, in a paid product, or in printed material at no charge.
- No per-pageview or per-domain fees. Traffic does not change the cost, which is zero.
- You may self-host. The license grants the right to copy the files to your own server. This is the legal basis for the self-hosting approach described later.
- You may bundle fonts in other deliverables, such as a PDF, an app, or a design file, subject to the license text. The OFL, for example, requires that the license accompany any redistributed copy of the font.
- Selling the font file on its own is not allowed under the OFL, and renaming a modified version is required if the font declares a Reserved Font Name.
A free license is still a license. The OFL and Apache texts apply to the font files, not to the Google Fonts API. The API is governed by Google's own terms and privacy information.
What "open license" does not mean
Open licensing does not guarantee quality or completeness. Some families have only a single weight, some cover a limited set of scripts, and some are display faces that are poor for body text. Two fonts that look alike may differ in how they handle hinting, kerning, or tabular numerals. Evaluate a font by testing it on real text, not by its presence in the catalog.
How the delivery service works
When you use the embed code, the browser performs a two-step fetch. The first request returns CSS. The second set of requests returns the font files that the CSS refers to.
Three details of this design matter in practice.
The CSS is generated per request
The css2 API builds its response from your query string. A request for Lora weights 400 and 700 returns @font-face rules for those two weights only. The display=swap parameter becomes font-display: swap in every returned rule.
The response also depends on the requesting browser. Google serves a format and a set of rules suited to the user agent, which today means WOFF2 for any current browser. You will see this if you fetch the CSS URL with curl: the output can differ from what a browser sees.
Subsetting through unicode-range
For families that support several scripts, the returned CSS contains many @font-face rules for the same family and weight, each with its own unicode-range and its own file. A page in English downloads the Latin file and never fetches the Cyrillic or Vietnamese files, even though their rules are present. You can verify this in the Network tab: the CSS may declare a dozen rules, while the page downloads one or two font files.
This is why you should not try to "optimize" by deleting subset rules from a copy of the CSS. The browser is already skipping what it does not need.
Two hosts, two roles
The stylesheet comes from fonts.googleapis.com, and the font files come from fonts.gstatic.com. The second host is a different origin, and font requests are made in CORS mode, which is why the recommended preconnect hint for it includes the crossorigin attribute. Leaving it out is a common mistake, because the browser then opens a connection that it cannot reuse for the font download.
Building API URLs by hand
The embed code is generated for you, but you will edit it often, so learn the css2 syntax. A complete page that loads two families follows.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Google Fonts demo</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&family=Roboto+Mono:wght@400&display=swap" rel="stylesheet">
<style>
body {
font-family: "Lora", Georgia, serif;
line-height: 1.6;
}
code {
font-family: "Roboto Mono", ui-monospace, Consolas, monospace;
}
</style>
</head>
<body>
<h1>Readable text</h1>
<p>Body text in <em>Lora</em>, with <code>inline code</code> in Roboto Mono.</p>
</body>
</html>The URL follows these rules:
- Each family is a separate
family=parameter. The first has no&before it, and each later one is joined with&. - Spaces in family names become
+, as inRoboto+Mono. - After the colon comes a list of axis names, then
@, then the tuples of values. - Within each family, tuples are separated by
;, and the values within a tuple by,. - Axis names must be sorted alphabetically, with lowercase axes before uppercase ones.
ital,wghtis valid andwght,italis not. - A tuple must supply a value for every axis you list. In
ital,wght@0,400;1,400,0,400means upright at weight 400, and1,400means italic at weight 400. display=swapis a single, separate parameter at the end of the URL, not part of any family.- A range such as
[email protected]requests the variable version of a family and is only valid for families that offer it.
Common errors
These are the problems you will most often meet when you work with Google Fonts.
- A 400 Bad Request from the API. The causes are an axis list in the wrong order, a weight the family does not offer, or a tuple that is missing a value. Open the stylesheet URL directly in a browser tab. The error message often names the problem.
- The font name in CSS does not match. The
font-familyvalue must match the family name in the returned@font-facerules. Check the CSS response if text does not change, because a typo such as"Roboto-Mono"silently falls through to the next font in the stack. - The wrong weight is displayed. If the CSS asks for
font-weight: 600but you loaded only 400 and 700, the browser uses the closest loaded weight, and in some cases it synthesizes bold or italic. Synthesized styles look distorted. Load the weights you use, or remove the ones you don't. - Missing
crossoriginon thefonts.gstatic.compreconnect. The page still works, but the early connection is wasted. - Loading everything "just in case". Requesting eight weights with italics for a design that uses two is a common source of slow first renders.
- Assuming a shared cache. Older advice says that a visitor probably already has Google's copy of a font cached from another site. Modern browsers partition their HTTP caches by site, so this no longer holds. Don't rely on it as a speed argument for hosted delivery.
Privacy and the hosted API
When a browser requests the CSS and fonts from Google's servers, those servers receive the visitor's IP address and standard request headers. Google's published FAQ states that the Google Fonts API does not set cookies and that it collects only the information needed to serve the files. Even so, a 2022 ruling by the Munich Regional Court held that embedding Google Fonts from Google's servers without the visitor's consent breached the GDPR, and the ruling led many European sites to self-host. Whether this applies to your project is a legal question. The technical fix is simple, because the OFL license lets you serve the files from your own domain. The self-hosting chapter shows how.
Summary of the working model
- The catalog and the delivery service are separate. The license lets you use the first without the second.
- Most fonts are OFL, some are Apache 2.0, and a few use the Ubuntu license. All allow commercial use at no cost.
- The
css2API builds CSS for exactly the families, axes, anddisplayvalue in your URL. - The returned CSS uses
unicode-range, so browsers fetch only the subsets that the page needs. - Most errors come from malformed axis lists, mismatched family names, and loading more styles than the design uses.
Exercise
A teammate writes this URL and gets a 400 error: https://fonts.googleapis.com/css2?family=Lora:wght,ital@400,0;700,0&display=swap. Identify the problem and write the corrected URL.
Show answer
The axis list is in the wrong order. Axes must be sorted alphabetically, so the list should be ital,wght, and each tuple must follow that order. The corrected URL is https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700&display=swap
Exercise
A client asks whether the company may use a Google Fonts family licensed under the SIL Open Font License on a paid product site, and whether the font files may be copied to the company's own server. What do you answer, and what one thing may the company not do with the font file?
Show answer
Yes to both. The OFL permits commercial use, and it permits redistribution and self-hosting, so the files may be served from the company's own domain. The company may not sell the font file on its own, and if it modifies the font and the font declares a Reserved Font Name, the modified version must not use that name.
Exercise
You load Lora with weights 400 and 700 but your CSS sets h2 to font-weight: 600. What does the browser do, and what are two ways to fix it?
Show answer
The browser uses the nearest loaded weight, and for a missing bold it may synthesize one, which can look distorted. Fix it by changing the CSS to use 700, or by adding 600 to the request (for example wght@400;600;700, or a range such as [email protected] if the family is variable).