Skip to content

CSS font-variant-numeric Property

The font-variant-numeric property supports the OpenType font format taking control of the usage of alternate glyphs for numbers, fractions, and ordinal markers.

Numbers can have variants such as ordinals (e.g. 1st), fractions (e.g. 1/2). Unlike letters, they don’t change the content’s meaning but these variations add additional context and can have an effect on legibility.

The main limitation is that only a limited number of fonts fully support font-variant-numeric and font-variant. There is a large number of OpenType-compatible fonts, but there aren’t many options that use all the features of font-variant-numeric.

Initial Valuenormal
Applies toAll elements. It also applies to ::first-letter and ::first-line.
InheritedYes.
AnimatableDiscrete.
VersionCSS3
DOM Syntaxobject.style.fontVariantNumeric = "slashed-zero";

Syntax

Syntax of CSS font-variant-numeric Property

css
font-variant-numeric: normal | <numeric-figure-values> | <numeric-spacing-values> | <numeric-fraction-values> | ordinal | slashed-zero;

Example of the font-variant-numeric property:

Example of CSS font-variant-numeric Property with oldstyle-nums and diagonal-fractions values

html
<!DOCTYPE html>
<html>
  <head>
    <title>The title of the document </title>
    <style>
      .p1 {
        font-variant-numeric: oldstyle-nums;
      }
      .p2 {
        font-variant-numeric: diagonal-fractions;
      }
    </style>
  </head>
  <body>
    <h2>Font-variant-numeric property example</h2>
    <p class="p1">001528931</p>
    <p class="p2">1/2</p>
  </body>
</html>

Result

CSS font-variant-numeric Property

Values

ValueDescription
normalAlternate glyphs are not enabled.
<numeric-figure-values>Controls the figure style. Keywords: lining-nums, oldstyle-nums.
<numeric-spacing-values>Controls the spacing width. Keywords: proportional-nums, tabular-nums.
<numeric-fraction-values>Controls the fraction style. Keywords: diagonal-fractions, stacked-fractions.
ordinalReplaces digits with superscript ordinal glyphs (e.g., ¹ˢᵗ, ²ⁿᵈ) instead of adding text like "st" or "nd". Maps to OpenType ordn.
slashed-zeroForces a zero with a slash. Maps to OpenType zero.
initialSets the property to its default value.
inheritInherits the property from its parent element.

Practice

What does the CSS font-variant-numeric property do?

Dual-run preview — compare with live Symfony routes.