Variable Fonts: Axes, font-variation-settings and Optical Sizing
One font file with continuous weights and widths: how variable fonts work, declaring their ranges in @font-face, the registered axes and their properties, custom axes with font-variation-settings, optical sizing, grade, animation and performance.
kvi5hnuCode Sprout team member6 min readOn this page
A traditional font family is a set of separate files: regular, bold, light, condensed, each a fixed design. A variable font is a single file that contains a design space: the type designer draws a few master designs, and the font can produce any point between them. Weight 437, width 88%, a slant of 6 degrees: all from one file.
The benefits:
- Fewer requests: one file instead of four or eight, and often a smaller total download once you'd use three or more static faces.
- Any value between the extremes, not just 400 and 700.
- Responsive and animated typography: weight or width can change with
clamp(), container size or a transition.
Axes
Each dimension a font can vary along is an axis, named by a four-letter tag. Five are registered, with standard meanings and their own CSS properties:

Use the normal properties for registered axes. Tested in Chrome with the macOS system font, which is variable, on the word "Harbour" at 40px:
font-weight: 450drew it 141.3px wide, between 139.2px at 400 and 143.5px at 500, so the weight varies continuously.font-stretch: 75%gave 120px, the same as setting thewdthaxis to 75 directly.
A font may support any combination of axes, each with its own range: one font might have weight 100–900 and width 75–100, another only weight 300–800. The font's documentation lists them, and browser DevTools show them in the Fonts panel.

All of these come from one font file: each property moves along an axis, and the axes combine freely.
Declaring a variable font
In @font-face, give the ranges the file supports, so the browser knows it can use this one file for all those values instead of synthesizing:
@font-face {
font-family: "Recursive";
src: url("recursive-var.woff2") format(woff2) tech(variations);
font-weight: 300 1000;
font-stretch: 75% 125%;
font-style: oblique 0deg 15deg;
font-display: swap;
}
h1 { font-family: "Recursive", sans-serif; font-weight: 850; font-stretch: 90%; }
body { font-family: "Recursive", sans-serif; font-weight: 420; }
If a single value like font-weight: 400 is given instead of a range, the browser treats the face as weight 400 only, and may synthesize bold on top of it for <strong>. If the family has a separate italic variable file, add a second @font-face with font-style: italic and the same family name (article 83).
font-variation-settings
For custom axes, which have uppercase tags, there's no dedicated property:
.button { font-variation-settings: "GRAD" 150; } /* grade: heavier without getting wider */
.logo { font-variation-settings: "CASL" 1, "MONO" 0; } /* axes of a particular font */
Like font-feature-settings (article 86), it's a single property: a later declaration replaces the whole list, and it overrides the properties for registered axes. Tested in Chrome: font-weight: 400 combined with font-variation-settings: "wght" 900 drew the text at 900. So avoid it for registered axes: if you use it for wght, font-weight: bold on a child stops working.
To combine settings without clobbering, use custom properties:
:root { --grad: 0; --casl: 0; }
.fancy { font-variation-settings: "GRAD" var(--grad), "CASL" var(--casl); }
.fancy.dark { --grad: -50; } /* change one axis only */
Optical sizing
Text at small sizes needs looser spacing, thicker thin strokes and larger openings to stay readable; display text can be finer and tighter. Fonts with an opsz axis contain both designs. With font-optical-sizing: auto, the default, the browser sets opsz from the font size automatically, so it works without any CSS.
font-optical-sizing: none turns that off. Tested in Chrome with the system font at 40px: forcing font-variation-settings: "opsz" 12, the small-text design, made "Harbour" 156.4px wide instead of 139.2px, because small-size designs are wider and more open.
Grade
Some fonts have a grade axis, usually GRAD, that changes the weight without changing the width. It's useful for:
- Dark mode, where light text on a dark background looks bolder: reduce grade slightly so it looks the same weight.
- Hover and focus states, where changing
font-weightwould make the text wider and shift the layout.
Animating axes
Weight, width and other axes animate smoothly, since the font can produce every value in between:
.link { font-weight: 400; transition: font-weight 0.2s; }
.link:hover { font-weight: 650; }
Changing weight or width changes the text's size, which causes layout work and can shift neighbours; grade avoids the shift. Respect prefers-reduced-motion (article 112) for anything more than a subtle hover.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
label { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.3rem; }
label input[type=range] { inline-size: 9rem; }
.sample {
font-family: system-ui, sans-serif; font-size: 2.6rem; margin: 0.6rem 0; line-height: 1.1; color: #8a3b12;
font-weight: var(--wg, 400); font-stretch: var(--wd, 100%);
}
.sample.opsz { font-variation-settings: "opsz" 12; }
.note { color: #555; }
Drag the weight slider: the text thickens continuously rather than jumping between two weights. With a variable system font, the width slider narrows and widens the letters themselves.
Performance
- A variable font file is larger than one static file, so if you only use regular and bold, two static files may be smaller. Beyond three or four styles, the variable file usually wins.
- Subset it (article 84), and drop axes you don't need with font tools, which can also limit ranges.
- Preload the variable file if it's used above the fold, since everything depends on it.
What's current
- Variable fonts,
font-variation-settingsandfont-optical-sizing: all browsers since 2020. - Ranges in
@font-facefor weight, stretch and oblique angles: all browsers. font-variation-settingsas an@font-facedescriptor: Chrome 140 and Firefox (article 83).
Common questions
Should I set weight with font-weight or font-variation-settings?
font-weight. It works with inheritance, bolder, and fallback fonts; font-variation-settings overrides everything and should be kept for custom axes.
Why does <strong> look synthesized with my variable font?
The @font-face rule gives a single weight instead of a range. Write font-weight: 100 900, or the font's actual range.
Is a variable font always smaller? No; compared with one or two static files it can be larger. It pays off when you use several styles.
What does optical sizing do?
It adjusts the design for the text size, through the opsz axis, automatically when the font has one.
Summary
- A variable font holds a continuous design space along axes, in one file.
- Registered axes (
wght,wdth,slnt,ital,opsz) are set withfont-weight,font-stretch,font-styleandfont-optical-sizing. - Declare ranges in
@font-face, likefont-weight: 100 900. font-variation-settingssets custom axes, but replaces its whole list and overrides the other properties; combine axes through custom properties.- Optical sizing is automatic; grade changes weight without changing width.
Practice questions
Write the @font-face rule for a variable WOFF2 font "Inter" with weights 100 to 900.
Answer
@font-face {
font-family: "Inter";
src: url("inter-var.woff2") format(woff2) tech(variations);
font-weight: 100 900;
font-display: swap;
}
Why does strong text stay at weight 350 here?
p { font-family: "Inter"; font-variation-settings: "wght" 350; }
strong { font-weight: 700; }
Answer
font-variation-settings is inherited and overrides font-weight for the wght axis, so strong is still drawn at 350. Use p { font-weight: 350; } instead.
A link should look bolder on hover without the text getting wider. What should change?
Answer
The font's grade axis, if it has one, for example font-variation-settings: "GRAD" 100 on hover. Grade changes stroke weight without changing letter widths, unlike font-weight.
When might two static files be better than one variable font?
Answer
When the page uses only regular and bold: the two static files can be smaller in total than the variable file, which contains the whole design space.
Previous: OpenType Features: font-variant, Numerals, Ligatures and font-feature-settings

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.