CSS Reference ยท Typography
The font-variation-settings property
Reference for the CSS font-variation-settings property: setting variable font axes such as wght, wdth, slnt and opsz, custom axes, pitfalls and live examples.
A variable font packs a whole range of designs into one file, controlled by axes such as weight (wght), width (wdth), slant (slnt) and optical size (opsz). The font-variation-settings property sets the value of those axes directly, using four-letter tags.
It is the low-level control for variable fonts. For the common axes, use the ordinary properties instead: font-weight, font-stretch, font-style and font-optical-sizing are easier to read and cascade correctly. Reach for font-variation-settings for custom axes that have no property of their own.
.title { font-variation-settings: "wght" 650, "wdth" 90; }
Try it
The example uses a variable font that ships with recent Windows (Bahnschrift). On a system without a variable font, all four lines look the same. With a variable web font loaded through @font-face the effect is identical on every device.
Syntax
font-variation-settings: normal | [ <string> <number> ]#;
| Initial value | normal |
| Applies to | All elements and text |
| Inherited | Yes |
| Animatable | Yes (axis values interpolate) |
| Computed value | As specified |
Values
| Value | Description |
|---|---|
normal |
The font's default axis values, or whatever the other font properties select. |
"tag" number |
Sets the axis named by a four-character tag to the number. Separate several axes with commas. |
Registered axes use lowercase tags: wght weight, wdth width, slnt slant angle, ital italic switch, opsz optical size. Custom axes use uppercase tags and are specific to the font.
Usage notes
- Prefer high-level properties.
font-weight: 650sets thewghtaxis, and it also affects fallback fonts and weight matching.font-variation-settingsdoes neither. - It overrides. If both are used,
font-variation-settingswins for the axes it names. Unlisted axes keep the values chosen by other properties. - Whole-value inheritance. A child's declaration replaces the parent's whole list. To change one axis only, use custom properties and compose the string:
font-variation-settings: "wght" var(--w), "wdth" var(--wd). - Tag errors fail silently. Unknown tags are ignored, and tags are case-sensitive. Values outside the font's range are clamped.
- Animation. Smooth axis animation (hover effects, scroll effects) is a good use, but check text reflow and respect
prefers-reduced-motion. - Fallbacks. Provide a sensible static font stack, because users without your variable font get the plain fallback.
Browser support
Variable fonts and this property are supported by all current browsers; check a compatibility table for older versions.