- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS Font-Variant-Alternates Enhance Web Typography
This property allows you to control alternate glyphs such as stylistic sets, swashes, ornaments, and annotations.
Introduction
The font-variant-alternates
CSS property lets you control alternate glyphs in your text. It’s a new feature available since March 2023 that enhances text appearance by enabling specific typographic features like stylistic sets, swashes, ornaments, and annotations. You don’t need to know specific index values for each font; just use this property with the @font-feature-values
at-rule to apply complex typographic styles easily.
Specification
The font-variant-alternates
property is defined in the CSS Fonts Module Level 4 specification. It works with the @font-feature-values
at-rule to map human-readable names to numeric indices for OpenType font features. This makes applying typographic styles simpler and more intuitive.
Syntax
Keyword Values
normal
: Deactivates alternate glyphs.historical-forms
: Enables historical forms.
Functional Notation Values
stylistic(user-defined-ident)
: Enables stylistic alternates for characters.styleset(user-defined-ident)
: Enables stylistic sets for characters.character-variant(user-defined-ident)
: Enables specific stylistic alternatives for characters.swash(user-defined-ident)
: Enables swash glyphs.ornaments(user-defined-ident)
: Enables ornaments.annotation(user-defined-ident)
: Enables annotations.
Global Values
initial
: Sets the property to its initial value.inherit
: Inherits the value from the parent element.unset
: Resets the property to its natural value.revert
: Resets the property to the value established by the user agent’s stylesheet.revert-layer
: Resets the property to its value in the previous cascade layer.
Values
The font-variant-alternates
property supports various values to control alternate glyphs.
Keyword Values
normal
: Deactivates alternate glyphs.historical-forms
: Enables historical forms.
Functional Notation Values
stylistic(user-defined-ident)
: Enables stylistic alternates.styleset(user-defined-ident)
: Enables stylistic sets.character-variant(user-defined-ident)
: Enables character variants.swash(user-defined-ident)
: Enables swash glyphs.ornaments(user-defined-ident)
: Enables ornaments.annotation(user-defined-ident)
: Enables annotations.
Global Values
inherit
: Inherits the value from the parent element.initial
: Sets the property to its initial value.unset
: Resets the property to its natural value.revert
: Resets the property to the user agent’s stylesheet value.revert-layer
: Resets the property to its value in the previous cascade layer.
Examples
Enabling Swash Glyphs
Use the @font-feature-values
at-rule to define a name for the swash
feature of a font, then apply it with font-variant-alternates
.
Using Historical Forms
Enable historical forms using the font-variant-alternates
property.
Applying Stylistic Sets
Use the @font-feature-values
at-rule to define a name for the styleset
feature of a font, then apply it with font-variant-alternates
.
Using Ornaments
Enable ornaments using the font-variant-alternates
property.
Applying Swash Glyphs
Browser Compatibility
Current Browser Support
As of the latest updates, the following browsers support the font-variant-alternates
property:
- Google Chrome: Supported in the latest versions.
- Mozilla Firefox: Supported from version 34.
- Apple Safari: Supported from version 9.1.
- Microsoft Edge: Supported in the latest versions.
Partial or No Support
Older versions of these browsers, and some less commonly used browsers, may not support this property. Always test your web designs across multiple browsers and versions.
Best Practices
- Fallback Options: Provide fallback options for browsers that don’t support
font-variant-alternates
. - Feature Detection: Use feature detection techniques to check if the property is supported.
- Graceful Degradation: Ensure your web design degrades smoothly in older browsers.
For the most up-to-date information on browser compatibility, refer to resources like Can I Use and MDN Web Docs.
Related Properties
font-variant
A shorthand property that controls several font-variant features at once, like font-variant-caps
, font-variant-ligatures
, and font-variant-numeric
.
font-variant-caps
Controls the use of alternate glyphs for capital letters, such as small-caps and petite-caps.
font-variant-east-asian
Controls the presentation of East Asian text, useful for multilingual web pages.
font-variant-emoji
Controls the presentation of emoji characters, ensuring consistent and appropriate use.
font-variant-ligatures
Controls the use of ligatures in text, such as common ligatures and discretionary ligatures.
font-variant-numeric
Controls the presentation of numeric characters, like old-style numbers and lining numbers.
font-variant-position
Controls the position of characters in text, useful for mathematical notation and chemical formulas.
@font-feature-values
Defines human-readable names for OpenType font features, making them easier to use in CSS.
font-feature-settings
Provides low-level control over OpenType font features, allowing you to enable or disable specific font features using numeric indices.
References
Official Specifications
- CSS Fonts Module Level 4: CSS Fonts Module Level 4 - font-variant-alternates-prop
MDN Web Docs
- MDN Web Docs - font-variant-alternates: MDN Web Docs - font-variant-alternates
Related CSS Properties Documentation
- MDN Web Docs - font-variant: MDN Web Docs - font-variant
- MDN Web Docs - font-variant-caps: MDN Web Docs - font-variant-caps
- MDN Web Docs - font-variant-east-asian: MDN Web Docs - font-variant-east-asian
- MDN Web Docs - font-variant-emoji: MDN Web Docs - font-variant-emoji
- MDN Web Docs - font-variant-ligatures: MDN Web Docs - font-variant-ligatures
- MDN Web Docs - font-variant-numeric: MDN Web Docs - font-variant-numeric
- MDN Web Docs - font-variant-position: MDN Web Docs - font-variant-position
- MDN Web Docs - @font-feature-values: MDN Web Docs - @font-feature-values
- MDN Web Docs - font-feature-settings: MDN Web Docs - font-feature-settings
Browser Compatibility
- Can I Use: Can I Use - font-variant-alternates
Additional Resources
- W3Schools - CSS Fonts: W3Schools - CSS Fonts
- CSS-Tricks - A Complete Guide to CSS Fonts: CSS-Tricks - A Complete Guide to CSS Fonts
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.