
For years, web developers and designers have faced a frustrating trade-off: do you want a beautiful, typographically diverse website, or do you want a fast one?
Traditionally, if you wanted to use a font like Roboto in Thin, Regular, Medium, and Bold—each with its own Italic counterpart—you had to force the browser to download eight separate files. This "font bloat" increased HTTP requests and slowed down page load times, often leading to the dreaded Flash of Uninvisible Text (FOIT).
Enter Variable Fonts. Formally known as OpenType Font Variations, this technology is the biggest shift in digital typography since the transition from bitmap to vector.
A variable font is a single font file that behaves like many. Instead of having separate files for every weight and style, a variable font contains "axes" of variation. These axes allow you to interpolate any value between a defined range.
Think of it like this: A traditional font is a set of static snapshots. A variable font is a fluid slider.
The primary benefit of variable fonts is the massive reduction in payload.
Instead of requesting five different files for various weights, the browser makes one request. Even if the variable font file is slightly larger than a single static file, it is almost always significantly smaller than the combined total of the static files it replaces.
Because you can access any value on an axis (e.g., a font-weight of 542 instead of just 500 or 600), you can fine-tune typography for specific screen sizes or resolutions without loading additional data.
By reducing the number of assets the browser needs to fetch before rendering text, variable fonts help improve Largest Contentful Paint (LCP) and reduce Cumulative Layout Shift (CLS) caused by fonts "popping in" late.
The "magic" of variable fonts happens through axes. There are five standard registered axes, though font creators can also define custom axes.
wght): Adjusts how thick or thin the characters are.wdth): Adjusts how narrow or wide the characters are.slnt): Adjusts the lean of the characters.ital): A binary toggle or range to turn on italic forms.opsz): Automatically adjusts letter spacing and stroke thickness based on the font size to improve readability.Some variable fonts go even further, offering axes for "Grade" (changing the weight without changing the width, useful for dark mode), "Serif height," or even "Flourish."
Using variable fonts in CSS is straightforward. You start by defining the font in your @font-face rule, ensuring you specify the range of the axes available.
@font-face {
font-family: 'Inter Variable';
src: url('Inter-VariableFont_slnt,wght.woff2') format('woff2-variations');
font-weight: 100 900;
font-style: oblique 0deg 10deg;
}
body {
font-family: 'Inter Variable', sans-serif;
}
/* Use standard properties where possible */
h1 {
font-weight: 850; /* A specific, non-standard weight */
}
/* Use font-variation-settings for custom or specific axes */
.dynamic-text {
font-variation-settings: 'wght' 500, 'wdth' 75;
}
While font-variation-settings is the "low-level" way to control axes, CSS has been updated so that standard properties like font-weight and font-stretch now map directly to the variable axes. It is best practice to use the standard properties whenever possible for better accessibility and readability.
To make the most of variable fonts, keep these tips in mind:
Variable fonts are no longer a "nice-to-have" experimental feature. They are a production-ready secret weapon. By combining the flexibility of a full type system with the performance of a single file, they allow developers to build web apps that are as beautiful as they are fast.
If you haven't made the switch yet, your next project is the perfect time to start.
Photo by Matias Mango on Pexels