Font-variant-alternates - CSS Property

font-variant-alternates

Summary of characteristics of the font-variant-alternates property

Quick description
Defines character substitution (OTF, WOFF fonts).
Status
Standard
Predefined values
normal | historical-forms | annotation(nalt) | character-variant(cv01) | ornaments(ornm) | styleset(ss01) | stylistic(styl) | swash(swsh)
Percentages
Not applicable.
Initial value
normal
Inherited by default
Yes.
Discrète: during an animation, the font-variant-alternates property passes from one value to another without transition.
Per grammar: serialization in the order of syntax. Values can be entered in any order.
W3C Module
CSS Fonts Module
Document status: WD (Working Draft)

Syntax diagram of font-variant-alternates.

Font-variant-alternates property - Syntax diagramSyntax diagram of the font-variant-alternates CSS property. See stylescss.free.fr for details. normal normal historical-forms historical-forms stylistic(...) stylistic(...) styleset(...) styleset(...) character-variant(...) character-variant(...) swash(...) swash(...) ornaments(...) ornaments(...) annotation(...) annotation(...)font-variant-alternates:;font-variant-alternates:;
Syntax diagram of the font-variant-alternates property.
The links in the diagram provide more details about the values.
Download the diagram.

Description of the font-variant-alternates property.

Many fonts often offer several glyphs for each character. There’s the standard glyph, but also the decorated variant, the historical version, the stylistic version, etc. font-variant-alternates lets you choose which variant should be used.

Unfortunately, there's no rule that requires the naming or ordering of these variants in a font. So you can't really write a CSS rule to select variant number 1 or variant number 3, because from one font to another, these variants, if they exist, wouldn't necessarily be equivalent.

For this reason, font-variant-alternates works in collaboration with the @font-feature-values directive:

  • @font-feature-values name the variants you want to use by indicating their family and their location in the chosen font.
  • font-variant-alternates apply these named variants to the elements of the HTML document.

The variants are still grouped by families: historical, decorative, stylistic, etc. The best thing is to explain all that with an example.

In the code below, the first directive @font-face shows the name of the font (Countryside) and where to download it.
The second directive (@font-feature-values) indicates that, for this font Countryside, the variant we call loops is the first of the swash family variants.
Finally, the property font-variant-alternates is used to apply this loops variant to the element with the ID id1.

@font-face{ font-family:'Countryside'; src:url('fonts/countryside.ttf'); } @font-feature-values Countryside { @swash {loops: 1;} } #id1 { font-family: 'Countryside', fantasy; font-variant-alternates: swash(loops); }

Which gives the result below (ultimately quite hard to read 😉 but without a doubt with some nice loops).

Beautiful curls, aren't they?


To complete these explanations, refer to the pages on the @font-face and @font-feature-values directives.

Values for font-variant-alternates.

  • font-variant-alternates: normal;

    Default value. No typographic processing is done. The glyphs of standard characters are used.

    Test.
    font-family:Warnrock;
    font-variant-alternates:normal;
  • font-variant-alternates: historical-forms;

    Activate the historical variant. These are usually characters whose shapes resemble old printing typefaces. Note that there’s no need to specify the name of the historical variant here, so a declaration with @font-feature-values isn’t necessary.

    This syntax is equivalent to font-feature-settings:'hist'.

    In the Warnock font used for the example, only the lowercase s is changed.

    Test.
    font-family:Warnrock;
    font-variant-alternates:normal;
    Test.
    font-family:Warnrock;
    font-variant-alternates:historical-forms;
  • font-variant-alternates: annotation(id);

    Activate one of the variants of the annotation family, the one whose name was set to id by @font-feature-values.

    Variants of the annotation type are characters that can be used for numbering (letters or numbers surrounded, for example).

    The same effect can be achieved with the property font-feature-settings:'nalt'.

    The font GotichA1 used in the example only includes the first 4 digits in the annotation variant.

    1 2 3 4
    font-family:GothicA1;
    font-variant-alternates:normal;
    1 2 3 4
    font-family:GothicA1;
    font-variant-alternates:annotation(…);
  • font-variant-alternates: character-variant(id);

    Activates one of the variants from the character-variant family, the one whose name was set to id by @font-feature-values.

    These variants generally allow you to display specific characters, for example to make them easier to type when they're not accessible on the keyboard. This corresponds to the OpenType codes cv01, cv02, etc.

    The same effect can be achieved with the font-feature-settings:'cv01' property (or cv02, cv03, etc., up to cv99).

    We don't have any fonts that include a character-variant(…) option: the example doesn't work.

    Sample.
    font-family:Warnrock;
    font-variant-alternates:normal;
    Sample.
    font-family:Warnrock;
    font-variant-alternates:character-variant(…);
  • font-variant-alternates: ornaments(id);

    Activate one of the variants from the ornaments family, the one whose name defined by @font-feature-values is id.

    Ornaments are graphic elements like fleurons, lines, bullets, etc. Some fonts offer a whole list of ornaments to spice up a design.

    Ornaments can also be displayed with the property font-feature-settings:'ornm'.

    a b c d e f g h
    font-family:Warnrock;
    font-variant-alternates:normal;
    a b c d e f g h
    font-family:Warnrock;
    font-variant-alternates:ornaments(…);
  • font-variant-alternates: styleset(id);

    Activates one of the variants of the styleset family, the one whose name defined by @font-feature-values is id.

    The styleset variants can also be displayed with the property font-feature-settings:'ss01' (or ss02, ss03, etc. up to ss20).

    To find an example that looks visually different, we had to choose the words. Indeed, few characters change between normal and styleset(ss01).

    This is the fabric.
    font-family:Comic-Jens;
    font-variant-alternates:normal;
    This is the fabric.
    font-family:Comic-Jens;
    font-variant-alternates:styleset(…);
  • font-variant-alternates: stylistic(id);

    Activate the variants of the stylistic family, whose name defined by @font-feature-values is id.

    These variants can also be displayed with the property font-feature-settings:'ss01'.

    This is the fabric.
    font-family:Comic-Jens;
    font-variant-alternates:normal;
    This is the fabric.
    font-family:Comic-Jens;
    font-variant-alternates:stylistic(…);
  • font-variant-alternates: swash(id);

    Activates the swash family variants, whose name defined by @font-feature-values is id.

    These variants usually correspond to very ornate characters, with extra loops, hooks, etc.

    Ornamental variants can also be displayed with font-feature-settings:'swsh'.

    Sample.
    font-family:Countryside;
    font-variant-alternates:normal;
    Sample.
    font-family:Countryside;
    font-variant-alternates:swash(…);
  • font-variant-alternates: swash(id) stylistic(id);

    As you can see in this syntax example, it's possible to combine several variants by separating them with a space.

  • font-variant-alternates: initial; (normal) font-variant-alternates: inherit; font-variant-alternates: revert; font-variant-alternates: revert-layer; font-variant-alternates: revert-rule; font-variant-alternates: unset;

    Links to the presentation of these different values: initial, inherit, revert, revert-layer, revert-rule, unset.

Animation of the font-variant-alternates property.

The box below shows what the animation of font-variant-alternates looks like. The effect is actually more interesting when the animation happens between two very similar variants.

Animation

Simulator.

The simulator activates the alternate glyphs of the font, as long as they exist. All the identifiers (ann, char, hist, etc.) were defined by a @font-feature-values directive for each of the fonts.

FontCountrysideWarnockComic-Jens
Historical XX
Annotation
Character...
Ornaments X
Styleset X
Stylistic X X
Swash X X
Police :
font-variant-alternates :
Let me try that old whiskey.

Browsers compatibility with font-variant-alternates.

Support for the font-variant-alternates property is now correct on the major current browsers. However, keep in mind that font-variant-alternates can only use the capabilities of the chosen font, and the variants offered in fonts aren't that many.

Column 1
Ability of browsers to control alternative glyphs for certain typefaces.

Notes:

(1) Use the low-level property font-feature-settings with the codes salt, ss01 to ss20, swsh, etc.

1
font-variant-alternates
property
Estimated overall support.
93%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Firefox

Safari

Safari sur IOS

Chrome

Opéra

Edge

Chrome pour Androïd

Firefox pour Androïd

Androïd Brower

KaiOS Browser

Opéra mini

Historic of the font-variant-alternates property.

  • CSS Fonts Module Level 4

    This level 4 of the specification on fonts reprises what is defined in level 3. It adds the possibility to define what happens when a font takes a long time to load or is missing. It also adds support for colored fonts and clarifies many points still poorly defined in level 3.

    Regarding font-variant-alternates:
    First presentation of the font-variant-alternates property.
    WD
    July 11, 2017
    Working Draft.
    CR
    PR
    REC

See also abor fonts.

The property font-variant-alternates, along with all those related to fonts, is grouped in the module CSS Fonts Module. You can find the following definitions in this module:

Properties:

font
Langue française
Shorthand to set most properties for fonts.
✗
font-effect
Langue française
Allows you to apply some effects to the text: relief, border...
font-family
Selects a font from those that are available or downloaded.
⚠
font-feature-settings
Langue française
Permet d’exploiter les fonctionnalités spécifiques des polices de caractères OTF, WOFF, etc.
font-kerning
Adjusting the kerning between characters.
⚠
font-language-override
Langue française
Defines the language to be considered when choosing characters.
⚠
font-optical-sizing
Langue française
Optimizes the shape of characters based on their size.
font-palette
Langue française
Defines the color palette that can be used for colored fonts.
font-size
Adjusts the font size, which also impacts units like em, ex, etc.
font-size-adjust
Langue française
Definition of the aspect factor of the font.
✗
font-smooth
Langue française
Defines whether and which smoothing algorithm should be used.
font-stretch
Langue française
Changes the stretching or compression of characters.
font-style
Langue française
Selects the italic or oblique font styles.
font-synthesis
Allows or disallows calculation of missing styles in the typeface.
⚠
font-synthesis-position
Langue française
Whether or not allows the browser to synthesize characters in superscript or subscript.
font-synthesis-small-caps
Langue française
Whether or not allows the browser to calculate the glyphs of characters in small caps.
font-synthesis-style
Langue française
Defines whether the browser is allowed to synthesize italic forms of characters.
font-synthesis-weight
Langue française
Defines whether or not the browser can calculate the bold glyph.
font-variant
Shorthand to define advanced typographic attributes: ligatures, character substitution, etc.
Font-variant-alternates
Defines character substitution (OTF, WOFF fonts).
font-variant-caps
Applies character capitalization.
font-variant-east-asian
Typography specific to Chinese or Japanese characters.
⚠
font-variant-emoji
Choose between an emoji or text presentation.
font-variant-ligatures
Enables or disables character ligation.
font-variant-numeric
Defines how evolved numbers are displayed: fractions, numbers, etc.
⚠
font-variant-position
Superscript or subscript of characters.
font-variation-settings
Provides access to the stylistic possibilities of OTF fonts.
font-weight
Selects a weight for the characters.
font-width
Langue française
Synonymous with font-stretch (character width/enlargement).

Functions:

⚠
palette-mix()
Langue française
Establish the mixture of two color palettes from two different typefaces.

At-rules:

@font-face
Langue française
Defines all settings for a downloadable font.
⚠
@font-feature-values
Langue française
Defines the typographic variations to use.
@font-palette-values
Langue française
Defines a color palette that can then be applied to a font.

Descriptors :

ascent-override
Langue française
Descriptor for @font-face. Sets the height of the characters above the baseline.
descent-override
Langue française
Descriptor for @font-face. Sets the height of the characters below the baseline.
⚠
font-display
Langue française
Descriptor for @font-face. Determines how the browser behaves when faced with fonts that take a long time to load.
line-gap-override
Langue française
Descriptor for @font-face. Sets the line spacing of the font.
src
Langue française
Defines the source of a font file to download, or an image to display.
unicode-range
Langue française
Descriptor for @font-face. Defines the range of character codes to be downloaded into a font.