CSS font-variant-position Property
The font-variant-position property controls whether text uses specially designed superscript or subscript glyphs from the selected font.
Superscripts appear above the normal text baseline, while subscripts appear below it. This property uses OpenType font features when available, allowing raised or lowered characters to retain proportions and stroke weights designed for their smaller size.
font-variant-position Syntax
The property accepts one of three values: normal, super, or sub.
Basic Syntax
selector {
font-variant-position: normal;
}
Superscript
.superscript {
font-variant-position: super;
}
Subscript
.subscript {
font-variant-position: sub;
}
CSS-Wide Keywords
.example {
font-variant-position: inherit;
}
.example {
font-variant-position: initial;
}
.example {
font-variant-position: unset;
}
.example {
font-variant-position: revert;
}
.example {
font-variant-position: revert-layer;
}
Only one position value can be specified at a time. The super and sub values cannot be combined in the same declaration.
Property Values
The three values determine whether normal, superscript, or subscript glyphs are requested.
| Value | Description |
|---|---|
normal |
Uses the font's normal glyph forms without requesting superscript or subscript variants. |
super |
Requests superscript glyphs designed to appear above the normal baseline. |
sub |
Requests subscript glyphs designed to appear below the normal baseline. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | normal |
| Inherited | Yes |
| Applies to | All elements and text |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
The visible result depends on the selected font and whether it provides the corresponding OpenType superscript or subscript features.
How It Works
The property requests specially designed glyph substitutions rather than simply reducing the font size and moving the characters vertically.
Normal Text
.normal-text {
font-variant-position: normal;
}
Superscript Text
.raised-text {
font-variant-position: super;
}
Subscript Text
.lowered-text {
font-variant-position: sub;
}
Designed Glyph Substitutions
When the font includes the requested feature, the browser may replace ordinary characters with glyphs specifically designed for superscript or subscript presentation.
Font Feature Availability
If the selected font lacks suitable glyphs, the browser does not necessarily produce the same appearance as traditional superscript or subscript styling.
Important Consideration
The property changes glyph presentation without changing the underlying characters. It does not create mathematical structure or change the meaning of the text.
The normal Value
The normal value uses ordinary glyph forms without requesting superscript or subscript substitutions.
Basic Example
.text {
font-variant-position: normal;
}
HTML Example
<p class="text">H2O and x2</p>
Default Appearance
Characters remain in their ordinary typographic forms unless another style or font feature affects their presentation.
Reset a Custom Setting
.formula {
font-variant-position: super;
}
.formula .regular-text {
font-variant-position: normal;
}
Important Consideration
The normal value does not override unrelated properties such as vertical-align or font-size. Those properties may still affect the position or size of text.
The super Value
The super value requests superscript glyphs designed to appear above the normal text baseline.
Basic Example
.exponent {
font-variant-position: super;
}
HTML Example
<p>x<span class="exponent">2</span> + y<span class="exponent">2</span></p>
OpenType Feature
The super value uses the OpenType sups feature.
Typical Uses
Superscript glyphs may be used for exponents, footnote markers, and other raised characters.
Designed Superscripts
Dedicated superscript glyphs can have adjusted stroke weights and proportions to remain readable at their reduced visual size.
Font Availability
Not all fonts include superscript glyphs for every character. Some provide only digits or a limited selection of letters.
Important Consideration
For meaningful superscript content, use the HTML <sup> element. The CSS property controls appearance but does not replace semantic markup.
The sub Value
The sub value requests subscript glyphs designed to appear below the normal text baseline.
Basic Example
.chemical-index {
font-variant-position: sub;
}
HTML Example
<p>H<span class="chemical-index">2</span>O</p>
OpenType Feature
The sub value uses the OpenType subs feature.
Typical Uses
Subscript glyphs may be used in chemical formulas, mathematical variables, and other notation requiring lowered characters.
Designed Subscripts
Dedicated subscript glyphs are designed with proportions and stroke weights suited to their smaller appearance.
Font Availability
Some fonts provide subscript digits but not a complete set of subscript letters or symbols.
Important Consideration
For meaningful subscript content, use the HTML <sub> element rather than relying on CSS alone.
Font Support and OpenType Features
The font-variant-position property relies on OpenType features provided by the selected font.
OpenType Feature Mapping
| CSS Value | OpenType Feature |
|---|---|
super |
sups |
sub |
subs |
Professional Text Fonts
Some professional fonts include specially designed superscript and subscript glyphs. The available character sets vary by typeface.
Custom Web Fonts
.formula {
font-family: "Example Serif", Georgia, serif;
}
.formula .exponent {
font-variant-position: super;
}
Fallback Fonts
If the preferred font is unavailable, the fallback font may lack the requested glyph substitutions.
Partial Character Coverage
A font may support superscript or subscript substitutions for digits but not for all letters and symbols.
Important Consideration
Browser support for the CSS property does not guarantee that the selected font includes the requested OpenType features.
Using sup and sub Elements
HTML provides the <sup> and <sub> elements for superscript and subscript content.
Superscript HTML
<p>The area is measured in m<sup>2</sup>.</p>
Subscript HTML
<p>Water has the formula H<sub>2</sub>O.</p>
Apply Font Variant Position
sup {
font-variant-position: super;
}
sub {
font-variant-position: sub;
}
Why Semantic Elements Matter
The HTML elements identify content as superscript or subscript. CSS controls its visual presentation.
Avoid Double Positioning
Browsers commonly apply reduced font sizes and vertical alignment to <sup> and <sub> elements. Adding OpenType superscript or subscript glyphs without adjusting those styles may cause characters to appear too small or incorrectly positioned.
Using Designed Glyphs
sup {
font-size: inherit;
vertical-align: baseline;
font-variant-position: super;
}
sub {
font-size: inherit;
vertical-align: baseline;
font-variant-position: sub;
}
This approach removes the usual size and baseline adjustments so the font's designed glyphs can provide the visual positioning. It should be used only after confirming suitable font support.
Important Consideration
When predictable superscript or subscript rendering is required across different fonts, retaining the browser's default HTML styling is often more reliable.
Comparison with vertical-align
The vertical-align property and font-variant-position can both affect the appearance of raised or lowered text, but they work differently.
Using vertical-align
.exponent {
font-size: 0.75em;
vertical-align: super;
}
Using font-variant-position
.exponent {
font-variant-position: super;
}
Key Differences
| Feature | font-variant-position | vertical-align |
|---|---|---|
| Primary purpose | Selects designed superscript or subscript glyphs. | Adjusts vertical alignment of inline-level or table-cell content. |
| Font feature required | Yes, for designed glyph substitution. | No. |
| Changes glyph design | Can substitute specially designed glyphs. | Does not substitute glyphs. |
| Changes font size automatically | No ordinary font-size reduction is requested. | No; a separate font-size declaration may be needed. |
Typical Fallback
.exponent {
font-size: 0.75em;
vertical-align: super;
}
This traditional approach does not depend on the font providing special superscript glyphs.
Important Consideration
Avoid applying both techniques without accounting for their combined effects. Otherwise, superscripts and subscripts may appear too high, too low, or too small.
Using font-feature-settings
The font-feature-settings property provides direct access to OpenType feature tags.
High-Level Superscript
.exponent {
font-variant-position: super;
}
Low-Level Superscript
.exponent {
font-feature-settings: "sups" 1;
}
High-Level Subscript
.index {
font-variant-position: sub;
}
Low-Level Subscript
.index {
font-feature-settings: "subs" 1;
}
Preferred Approach
Use font-variant-position when selecting superscript or subscript glyphs. Use font-feature-settings when direct control over specific OpenType tags is required.
Important Consideration
Low-level font feature settings can override corresponding high-level font variant controls. Avoid conflicting declarations unless the interaction is intentional.
The font-variant Shorthand
The font-variant shorthand can set superscript or subscript features alongside other font variants.
Longhand Example
.exponent {
font-variant-position: super;
}
Shorthand Example
.exponent {
font-variant: super;
}
Combining Superscript with Numeric Features
.exponent {
font-variant: super lining-nums;
}
Shorthand Reset Behavior
.exponent {
font-variant-position: super;
font-variant: small-caps;
}
The later shorthand resets font-variant-position to normal because the position setting is not included.
Preserving Both Features
.exponent {
font-variant: super small-caps;
}
Important Consideration
Use font-variant-position when changing only the superscript or subscript feature. Use the shorthand when several font variant categories need to be defined together.
Inheritance
The font-variant-position property is inherited. Child elements receive the parent's setting unless they specify another value.
Inherited Superscript Setting
.superscript-group {
font-variant-position: super;
}
<span class="superscript-group">
<span>2</span>
<span>3</span>
</span>
Override a Child Element
.superscript-group {
font-variant-position: super;
}
.superscript-group .regular-text {
font-variant-position: normal;
}
Explicit Inheritance
.child {
font-variant-position: inherit;
}
Reset to Initial Value
.child {
font-variant-position: initial;
}
Important Consideration
Apply superscript and subscript styling to the specific characters that require it. Applying the property to an entire paragraph or container may affect more text than intended.
font-variant-position Example
This example compares ordinary text with superscript and subscript glyph requests. The visible differences depend on the selected font's OpenType support.
HTML Example
<div class="font-variant-position-demo">
<p class="demo-label">Normal text</p>
<p>x2 and H2O</p>
<p class="demo-label">Superscript glyph</p>
<p>x<span class="demo-super">2</span> + y<span class="demo-super">2</span></p>
<p class="demo-label">Subscript glyph</p>
<p>H<span class="demo-sub">2</span>O</p>
<p class="demo-label">Standard HTML elements</p>
<p>x<sup>2</sup> and H<sub>2</sub>O</p>
</div>
CSS Example
.font-variant-position-demo {
font-family: Georgia, serif;
}
.font-variant-position-demo p {
margin: 0 0 16px;
font-size: 26px;
line-height: 1.6;
}
.font-variant-position-demo .demo-label {
margin-bottom: 4px;
font: 600 13px/1.4 Arial, sans-serif;
}
.font-variant-position-demo .demo-super {
font-variant-position: super;
}
.font-variant-position-demo .demo-sub {
font-variant-position: sub;
}
Normal text
x2 and H2O
Superscript glyph
x2 + y2
Subscript glyph
H2O
Standard HTML elements
x2 and H2O
The superscript and subscript examples request designed glyph substitutions. The final example uses the browser's default presentation of the semantic HTML elements.
If the selected font does not provide suitable OpenType features, the CSS examples may look similar to ordinary text. The HTML <sup> and <sub> elements provide a more predictable fallback.
Common Mistakes
Common mistakes involve invalid values, unsupported font features, and confusion between glyph substitution and traditional baseline positioning.
Combining super and sub
.text {
font-variant-position: super sub;
}
This declaration is invalid because the property accepts only one position value.
Using superscript as a Value
.text {
font-variant-position: superscript;
}
This declaration is invalid. Use super.
Using subscript as a Value
.text {
font-variant-position: subscript;
}
This declaration is invalid. Use sub.
Expecting Every Font to Support the Features
Many fonts provide only a limited selection of superscript or subscript glyphs.
Applying the Property to an Entire Paragraph
Superscript and subscript styling should usually be limited to the specific characters requiring it.
Combining Designed Glyphs with Default HTML Positioning
Using font-variant-position on <sup> or <sub> without considering their default styles may cause excessive size reduction or vertical movement.
Using CSS Instead of Semantic HTML
Use <sup> and <sub> when the raised or lowered position is part of the content's meaning.
Ignoring Shorthand Reset Behavior
A later font-variant declaration may reset font-variant-position to normal.
Important Considerations
Keep the following points in mind when using the font-variant-position property:
- Purpose: Selects designed superscript or subscript glyphs.
- Property type: Longhand of
font-variant. - Initial value:
normal. - Inheritance: The property is inherited.
- Applies to: All elements and text.
- normal: Uses ordinary glyph forms.
- super: Requests superscript glyphs.
- sub: Requests subscript glyphs.
- OpenType superscripts: Use the
supsfeature. - OpenType subscripts: Use the
subsfeature. - Font support: The selected font must provide suitable glyph substitutions.
- Character coverage: Not every font supports every superscript or subscript character.
- Semantic HTML: Use
<sup>and<sub>for meaningful raised or lowered content. - vertical-align: Adjusts vertical positioning without selecting specially designed glyphs.
- Font size: The property does not simply reduce the ordinary font size.
- Text content: Glyph substitution does not change the underlying characters.
- Shorthand reset: A later
font-variantdeclaration may reset the property. - Fallback: Traditional HTML superscript and subscript styling is more predictable when font support is uncertain.
- Browser support: Check compatibility and OpenType feature availability.
Use font-variant-position when a font provides carefully designed superscript or subscript glyphs. For meaningful notation, preserve semantic HTML markup and test the appearance with the intended font.
Browser Support
The CSS font-variant-position property has Limited availability across browsers. Support and rendering behavior may vary between browser engines and versions.
Even when the property is recognized, the selected font must include the appropriate OpenType features for the requested glyph substitutions to appear.
Basic Example
.exponent {
font-variant-position: super;
}
Feature Detection
@supports (font-variant-position: super) {
.exponent {
font-variant-position: super;
}
}
Progressive Enhancement
When broad compatibility is required, use semantic HTML and retain the browser's normal superscript or subscript styling.
<p>x<sup>2</sup> + y<sup>2</sup></p>
<p>H<sub>2</sub>O</p>
Font Feature Availability
The @supports rule checks whether the browser recognizes the CSS declaration. It does not confirm that the selected font provides the required superscript or subscript glyphs.
For current compatibility information, visit Can I Use? and search for font-variant-position.
Specifications
The font-variant-position property is defined in the CSS Fonts Module, which describes superscript and subscript glyph selection using OpenType font features.
CSS Fonts Module Level 4: font-variant-position
The module also defines the font-variant shorthand and other typographic feature controls.
For additional explanations and examples, see MDN Web Docs.
