character-variant() CSS Function
The character-variant() function selects character variants of a font (OpenType cvXX), such as an alternative a or g, with font-variant-alternates.
Description
The character-variant() CSS function is one of the functions used with the font-variant-alternates property to switch on alternative glyphs in an OpenType font. It enables character variants: alternative forms for one specific character, such as a slashed zero or an alternative "l". It maps to the OpenType cv01 to cv99 features, and each variant feature can offer several glyph choices.
The argument is not a number but a name that you define yourself in a @font-feature-values rule for the font family, inside a @character-variant block. That rule maps the friendly name to the numeric index the font uses, so the same name can mean different glyph sets in different fonts. If the font has no matching feature, or no name is defined, the text is shown with its normal glyphs.
In the @character-variant block, a name maps to one or two numbers: the character variant feature, and optionally which of its glyphs to use. Several names can be given, separated by commas.
@font-feature-values "JetBrains Mono" {
@character-variant {
slashed-zero: 4;
alt-l: 1 2; /* cv01, second alternate */
}
}
code {
font-family: "JetBrains Mono", monospace;
font-variant-alternates: character-variant(slashed-zero, alt-l);
}
Syntax
character-variant() = character-variant( <feature-value-name># )
Values
- <feature-value-name>A <custom-ident> defined in the @character-variant block of an @font-feature-values rule for the font family. It maps to the font's OpenType cvXX (character variants) feature. Several comma-separated names can be given.
Example
Browser Support
The following information will show you the current browser support for the CSS character-variant() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





