Variable Fonts and font-variation-settings
- CSS Basics
- Selectors & Specificity
- Box Model & Units
- Typography & Text Styling
- Colors & Color Spaces
- Positioning & Stacking Context
- Flexbox
- Grid
- Grid Advanced
- Responsive Design
- Container Queries
- Pseudo-classes & Pseudo-elements
- Modern Selectors
- CSS Custom Properties
- CSS Functions
- Transitions & Animations
- Transforms
- Forms & Input Styling
- CSS Architecture & Methodologies
- Accessibility in CSS
- Performance & Optimization
- View Transitions & Modern APIs
- Cascade Layers & Scope
What a Variable Font Is
A traditional font family ships as separate files for each weight and style - regular, bold, italic, and so on. A variable font packs every one of those variations into a single file, with continuous axes that can be dialed to any value in between, not just the few fixed steps a designer originally shipped.
Using font-variation-settings
h1 {
font-family: "Inter Variable", sans-serif;
font-variation-settings: "wght" 650, "slnt" -3;
}Here, "wght" and "slnt" are axis tags defined by the font itself - weight and slant in this example - and each is set to a precise numeric value rather than picking from preset keywords like bold.
Common Standard Axes
| Axis tag | Controls |
|---|---|
wght | Weight, often from 100 to 900 |
wdth | Width - condensed to expanded |
slnt | Slant angle |
ital | Switches an italic variant on or off |
A Practical Benefit: Smooth Transitions
.btn {
font-variation-settings: "wght" 400;
transition: font-variation-settings 0.2s ease;
}
.btn:hover {
font-variation-settings: "wght" 650;
}Because the weight axis is a continuous number, it can be transitioned smoothly on hover - something impossible with fixed-weight font files, which can only jump between the separate files that were shipped.
Why Variable Fonts Matter
A single variable font file often replaces what would otherwise be six or more separate font files, reducing the total download size while giving far more typographic flexibility.