CSS font-variant-position
The font-variant-position property is used to enable typographic subscript and superscript glyphs.
One of the advanced features of OpenType typefaces is support for professionally designed subscript and superscript glyphs. Professionally designed subscript and superscript glyphs are designed to be visually compatible with the full-size figures in terms of weight and proportions. These glyphs are designed within the same em-box as default glyphs and are intended to be laid out on the same baseline as the default glyphs, with no resizing or repositioning of the baseline.
The font-variant-position property allows us to take advantage of these proper, true-drawn subscripts and superscripts (also known as "inferiors" and "superiors").
These subscript and superscript glyphs are a perfect match for the sub and sup elements. Without the proper glyphs, the user agent needs to take a normal glyph, and resize it and reposition its baseline. This usually has less than optimal results. The glyph often looks slightly unproportional, and its repositioning can affect the line height. Properly designed glyphs will overcome these issues.
Subscript/superscript support varies by typeface. Some typefaces have only basic support for numerals, while others contain subscript and superscript glyphs for a full set of letters, numerals, and punctuation. If a variant glyph isn't available for all characters in the run, the user agent will simulate glyphs for all characters (just as it would have done if this feature wasn't applied or available). This prevents having a mixture of proper variant glyphs and synthesized ones that don't align correctly.
Syntax
The syntax of the font-variant-position property is:
These values are explained in more detail below.
Possible Values
normal- Specifies that neither subscript variants nor superscript variants are enabled.
sub- Enables subscript variants (OpenType feature:
subs). super- Enables superscript variants (OpenType feature:
sups).
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial- Represents the value specified as the property's initial value.
inherit- Represents the computed value of the property on the element's parent.
unset- This value acts as either
inheritorinitial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
General Information
- Initial Value
normal- Applies To
- All elements
- Inherited?
- Yes
- Media
- Visual
- Animatable?
- No
Example Code
This example uses the @supports at-rule to apply styles only if the user agent supports the font-variant-position property.
In cases where the user agent doesn't support the font-variant-position property, it will use its own default styles for the sub and sup elements, which might look like this:
Official Specifications
- CSS Fonts Module Level 4
- CSS Fonts Module Level 3 (W3C Recommendation 20 September 2018)
Browser Support
Browser support for CSS properties can vary, particularly for newer or experimental features. Check current browser compatibility before using a property in production, especially when supporting older browsers.
Initial Value
CSS properties have an initial value that applies when the property has not been explicitly set. The initial value is different from the value inherited from a parent element and may vary between properties.
Inheritance
Some CSS properties inherit their computed value from their parent element by default, while others do not. The inherit, initial, unset, and revert keywords can also be used to control how a property gets its value.
Vendor Prefixes
Most modern CSS properties use the standard, unprefixed syntax. Vendor-prefixed properties such as -webkit- are mainly relevant to older browser versions or specific features and should only be used when required by your browser support targets.