- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS Font-Variant-Position Enhance Typography with Superscript and Subscript
Learn about its use cases, available options like 'normal', 'sub', and 'super', and how to incorporate it into your web design projects for improved typography.
Introduction
The font-variant-position
CSS property helps web developers control the use of alternate glyphs for superscript and subscript text. Introduced in September 2023, this feature is now widely supported on the latest devices and browsers. It enhances the visual appeal and readability of text without affecting line-height or other box characteristics.
Description
The font-variant-position
property is designed to control the use of alternate glyphs for superscript and subscript text. These glyphs are positioned relative to the baseline of the font, which remains unchanged. This property is particularly useful for elements like <sub>
and <sup>
.
When the property is activated, if any character in a text run lacks the appropriate glyph, the entire set of characters in the run is rendered using a fallback method. This ensures consistent typography and a seamless visual experience. These alternate glyphs share the same em-box and baseline as the rest of the font, providing a visually coherent appearance.
Syntax
The font-variant-position
property is specified using one of the keyword values listed below. These values determine how the text should be displayed—either as normal, superscript, or subscript.
Values
The font-variant-position
property can take several keyword values that determine how the text should be displayed relative to the baseline of the font.
normal
Deactivates the use of alternate superscript and subscript glyphs. Text is displayed in its default position relative to the baseline.
sub
Activates subscript alternate glyphs. Characters with subscript glyphs will be displayed as subscripts. If any character lacks a subscript glyph, the entire set of characters in the run will be rendered using synthesized glyphs.
super
Activates superscript alternate glyphs. Characters with superscript glyphs will be displayed as superscripts. If any character lacks a superscript glyph, the entire set of characters in the run will be rendered using synthesized glyphs.
Global Values
inherit
: Inherits the value from its parent element.initial
: Sets the property to its initial value (normal
).revert
: Resets the property to its default value defined by the user agent stylesheet.revert-layer
: Resets the property to its default value, considering the cascade layer it belongs to.unset
: Resets the property to its inherited value if it inherits from its parent, or to its initial value if not.
Formal Definition
The font-variant-position
property has specific characteristics that govern its behavior and application.
Property | Value |
---|---|
Initial Value | normal |
Applies To | All elements and text. It also applies to ::first-letter and ::first-line . |
Inherited | Yes |
Computed Value | As specified |
Animation Type | Discrete |
Formal Syntax
Examples
Example: Using font-variant-position: normal
HTML
Output
The output will display the text “(Website)2” with the “2” in its default position relative to the baseline.
Example: Using font-variant-position: super
HTML
Output
The output will display the text “(Website)²” with the “2” as a superscript.
Example: Using font-variant-position: sub
HTML
Output
The output will display the text “H₂O₂” with the “2”s as subscripts.
Combined Example
HTML
CSS
Result
The above code will render three paragraphs:
- The first paragraph will display “Normal!” in its default position.
- The second paragraph will display “Super!” as superscript text.
- The third paragraph will display “Sub!” as subscript text.
Specifications
The font-variant-position
CSS property is defined in the CSS Fonts Module Level 4. This module provides comprehensive specifications for various font-related properties, including font-variant-position
. The specifications outline the behavior, syntax, and usage of this property, ensuring consistency and interoperability across different browsers and platforms.
CSS Fonts Module Level 4
The CSS Fonts Module Level 4 is a critical part of the CSS standard, detailing how fonts and typography should be handled in web design. The font-variant-position
property is specifically addressed in this module, providing clear guidelines on its implementation and use.
Browser Compatibility
The font-variant-position
CSS property is a relatively new feature introduced in September 2023. It’s essential to check its compatibility across different browsers and devices to ensure consistent display for all users.
Browser Support
Here’s a quick overview of the browser compatibility for the font-variant-position
property:
- Google Chrome: Supported in the latest versions.
- Mozilla Firefox: Supported in the latest versions.
- Safari: Supported in the latest versions.
- Microsoft Edge: Supported in the latest versions.
- Opera: Supported in the latest versions.
Older versions of these browsers may have limited or no support. Always test your projects across multiple browsers and devices for consistent user experience.
Compatibility Resources
Stay informed about the latest compatibility information with these resources:
- MDN Web Docs Browser Compatibility for
font-variant-position
- Can I Use: Provides up-to-date browser support info.
Fallback Strategies
For older browsers that don’t support the font-variant-position
property, consider using fallback strategies. For example, use feature detection with JavaScript to apply alternative styling.
Example of feature detection with JavaScript:
See Also
If you found the font-variant-position
property useful, you might also be interested in these related CSS properties:
font-variant
: Controls various typographic features.font-variant-alternates
: Enables the use of alternate glyphs.font-variant-caps
: Controls the use of alternate glyphs for uppercase and lowercase letters.font-variant-east-asian
: Designed for East Asian typography.font-variant-emoji
: Controls the presentation of emoji characters.font-variant-ligatures
: Controls the use of ligatures.font-variant-numeric
: Controls the use of alternate glyphs for numeric characters.
Exploring these properties can help you create more sophisticated and visually appealing typography in your web projects.
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.