CSS @stylistic At-Rule
The @stylistic at-rule assigns a custom name to an OpenType stylistic alternate for a font family.
It appears inside @font-feature-values and works with font-variant-alternates: stylistic().
Syntax
@font-feature-values "Alternate Font" {
@stylistic {
elegant: 1;
}
}
The @stylistic block is nested inside @font-feature-values. Each descriptor gives a custom name and one positive integer that selects an OpenType stylistic alternate.
How @stylistic Works
The custom name is used with font-variant-alternates: stylistic(). The font’s OpenType salt feature supplies the actual glyph alternatives.
.heading {
font-family: "Alternate Font", serif;
font-variant-alternates: stylistic(elegant);
}
A named mapping is meaningful only when the selected font contains the corresponding OpenType glyph substitutions. The rule does not add glyphs to a font.
Font Requirements
Choose an OpenType font with the salt feature and a matching alternate index. Merely assigning a name does not ensure a visible change.
Load the font with @font-face when it is not installed locally, and confirm its licensing permits web embedding.
Single Index
@font-feature-values "Alternate Font" {
@stylistic {
alternate-a: 1;
alternate-b: 2;
}
}
Each named @stylistic descriptor selects one index. For a named group of multiple alternate indexes, use @styleset instead.
Using Named Alternates
.title {
font-family: "Alternate Font", serif;
font-variant-alternates: stylistic(alternate-a);
}
The mapping is associated with the specified font family. If the font is replaced by a fallback font, the named alternate may not produce a visual effect.
Fallback Appearance
If a browser does not support the named alternate, or the font lacks the requested glyph, text normally retains its standard glyph forms. Always keep the text readable without the alternate.
Do not rely on a stylistic alternate to convey essential information.
@stylistic Example
This example defines a readable name for a stylistic alternate. Replace the placeholder font with one that provides the requested feature.
HTML
<h2 class="sample-title">Sample typography</h2>
CSS
@font-feature-values "Alternate Font" {
@stylistic {
elegant: 1;
}
}
.sample-title {
font-family: "Alternate Font", serif;
font-variant-alternates: stylistic(elegant);
}
Preview: The alternate appearance depends on the actual font. A generic Browser Result would not reliably demonstrate the salt glyph substitution.
Browser Support
Support for @font-feature-values, @stylistic, and font-variant-alternates varies by browser and version. Verify the relevant features at Can I Use? , and test with a suitable font.
Specifications
The @stylistic rule is described in CSS Fonts Module Level 4.
