CSS Reference ยท At-rules
The @font-feature-values at-rule
Reference for the CSS @font-feature-values at-rule: give friendly names to OpenType alternates, then use them with font-variant-alternates.
The @font-feature-values at-rule lets you give readable names to numbered OpenType alternates inside a particular font family, such as "the third stylistic set" or "the fancy swash capital". You then switch them on with font-variant-alternates, using the name instead of a number.
Different fonts number their features differently, so the names live next to the font family they belong to. Changing the font means changing only this block, not every rule that uses the feature.
@font-feature-values "Fancy Serif" { @styleset { alt-a: 1; round: 3; } @swash { flourish: 2; } }
Try it
The effect depends on a font that contains these features, which system fonts usually do not. The text below is still visible, and with a suitable font the alternates appear.
Syntax
@font-feature-values <family-name># { @stylistic { <name>: <number>; } @historical-forms { <name>: <number>; } @styleset { <name>: <number>+; } @character-variant { <name>: <number>{1,2}; } @swash { <name>: <number>; } @ornaments { <name>: <number>; } @annotation { <name>: <number>; } }
Each inner block is a feature value block. The names are your own identifiers; the numbers are the font's feature indices. They are used through font-variant-alternates: stylistic(), styleset(), character-variant(), swash(), ornaments(), annotation() and historical-forms.
Values
| Syntax and arguments | Description |
|---|---|
@stylistic { name: n; } |
One stylistic alternate (salt). |
@styleset { name: n n; } |
One or more style sets (ss01-ss20). |
@character-variant { name: n; } |
Character variants (cv01-cv99). |
@swash { name: n; } |
Swash glyphs (swsh, cswh). |
@ornaments { name: n; } |
Ornament glyphs (ornm). |
@annotation { name: n; } |
Annotated forms such as circled digits (nalt). |
@historical-forms { name: n; } |
Historical forms (hist). |
Usage notes
- The family name must match the
font-familythe text uses, otherwise the names are not found. - Low-level alternative.
font-feature-settings: "ss03"or"swsh" 2toggles the same features directly, without this at-rule. Named values are friendlier butfont-feature-settingshas wider support. - Prefer
font-variant-*properties overfont-feature-settingswhen one exists. - Rarely needed. Most sites use only
font-variant-numeric,font-variant-ligaturesandfont-variant-caps. - Unknown names in
font-variant-alternatesare ignored, so a typo silently does nothing. - A font needs the feature. Check the font's documentation for its stylistic sets and numbers.
Browser support
Limited and uneven: it works in some engines and is missing or incomplete in others. Treat it as a progressive enhancement and test in the browsers you support.
Related
@font-face@font-palette-values- Lesson: Web Fonts
- Lesson: Text Styling