Sub topic 8
Loading only the weights and styles you need, and using variable fonts
This chapter assumes you can write a <link> tag, use the CSS font-family and font-weight properties, and check network requests in your browser's developer tools. You should also know how a font-family stack works from the previous chapter.
Why weights and styles cost something
Each weight and style of a typeface is a separate font file. Regular (400), bold (700), and italic are three different downloads. Every extra file adds bytes and delays text rendering. Font services let you request only the files you plan to use, so the usual rule is to ask for the smallest set that covers your design.
A typical page needs two or three weights: regular for body text, bold for headings and emphasis, and perhaps italic for quotes. Requesting all nine weights of a family because "we might need them" is the most common font performance mistake.
Requesting specific weights from Google Fonts
The css2 API takes the weights you want in the family parameter. Axes are listed after a colon, and values after @.
<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=Inter:wght@400;700&display=swap" rel="stylesheet">This loads Inter at weights 400 and 700 only. Separate the values with semicolons. If your CSS then asks for font-weight: 600, the browser has no 600 file. It picks the nearest available weight, which here is 700. The page still works, but the result is not what you designed.
To add italics, include the ital axis. Axis tuples must be sorted, and every tuple lists the same axes:
<link href="https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;1,400&display=swap" rel="stylesheet">Here 0,400 means upright at weight 400, and 1,400 means italic at weight 400. An unsorted or malformed list makes the API return an error (HTTP 400) and no font loads.
Variable fonts
A static font file holds one weight. A variable font is a single file that holds a continuous range along one or more axes, such as weight (wght) or width (wdth). Instead of three files for three weights, you download one file and use any weight in its range.
Use a range with two dots instead of a list:
<link href="https://fonts.googleapis.com/css2?family=Inter:[email protected]&display=swap" rel="stylesheet">Now any weight from 100 to 900 works in CSS, including values between the usual steps:
body {
font-family: "Inter", system-ui, sans-serif;
font-weight: 400;
}
h1 {
font-weight: 800;
}
.lede {
font-weight: 550;
}The 550 value would snap to a neighbor with static files. With the variable file it renders as written.
You can narrow the range to reduce size, for example [email protected], when you never use the extremes.
Weights and styles in Adobe Fonts
Adobe Fonts works differently. You choose weights and styles inside a web project on the Adobe Fonts site. For each family you tick the specific styles you want, such as Proxima Nova Regular and Bold. The project's stylesheet then includes only those.
<link rel="stylesheet" href="https://use.typekit.net/your-project-id.css">h1, h2 {
font-family: "proxima-nova", Helvetica, Arial, sans-serif;
font-weight: 700;
}Replace your-project-id with your own ID. If you later need another weight, edit the project on the Adobe site. The stylesheet URL stays the same, but its contents change. Some families in Adobe Fonts are offered as variable fonts. Check the family's page for this, because not all are.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Bold text looks only slightly heavier | Only 400 was loaded, so the browser makes a fake bold | Add `700` to the request |
| Italic looks slanted but distorted | No italic file loaded, so the browser slants the upright font | Request the italic style |
| `600` renders as `700` | Only 400 and 700 were requested | Request 600 or use a variable range |
| Font does not load at all | Malformed `css2` URL, such as unsorted axes | Check the request status in the Network panel |
| Unused weights downloaded | Request lists more weights than the CSS uses | Remove the extras |
The first two rows are called synthesized styles. The browser invents bold or italic when the real file is missing. The result is usually uneven and looks wrong next to a true bold or italic.
Checking what you load
Open developer tools, go to the Network panel, and filter by "Font". Reload the page. Each row is one font file with its size. Compare that list to the weights your CSS uses. Any file with no matching rule can be removed from the request.
Exercise
Your page uses Inter at weight 400 for body text, 700 for headings, and 400 italic for quotes. Write the Google Fonts link URL that loads only these three styles.
Show answer
https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;1,400&display=swap — the tuples are sorted with upright (0) before italic (1), and each lists both axes.
Exercise
Your CSS sets font-weight: 600 on subheadings, but the page loads Inter with wght@400;700. What weight does the browser show, and what are two ways to fix it?
Show answer
The browser shows 700, the nearest available weight. Fix it by adding 600 to the request (wght@400;600;700) or by switching to a variable range such as [email protected].