W3docs

CSS font-variant-numeric Property

The CSS font-variant-numeric property takes control of the usage of alternate glyphs for numbers, fractions, and ordinal markers.

The CSS font-variant-numeric property controls the use of alternate glyphs for numbers, fractions, and ordinal markers. It is a shorthand-friendly part of the font-variant family that exposes OpenType numeric features without dropping to the low-level font-feature-settings property.

This page covers what each value does, when to reach for it, the gotchas around font support, and a runnable example.

Why use it

Numbers can be rendered in several styles: ordinals (e.g. 1st), fractions (e.g. ½), lining vs. old-style figures, and proportional vs. tabular spacing. Unlike letters, these variants don't change the meaning of the text, but they add context and affect legibility:

  • Tabular figures make every digit the same width so numbers line up in tables and price columns.
  • Old-style figures have ascenders and descenders that blend into running prose instead of standing out like a heading.
  • Slashed zero disambiguates 0 from the letter O in code, IDs, and serial numbers.
  • Diagonal fractions turn 1/2 into a single typeset ½ glyph.

The main limitation is font support: the feature only works if the typeface actually ships the corresponding OpenType table. Most system fonts support a few features (lining, tabular), but diagonal-fractions, stacked-fractions, and slashed-zero are present in far fewer faces. When a font lacks a feature the value is silently ignored and the default glyphs are shown.

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

Syntax

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

The figure, spacing, fraction, ordinal, and slashed-zero values can be combined in a single declaration because they control independent aspects of the glyphs:

/* Tabular lining digits with a slashed zero */
font-variant-numeric: tabular-nums lining-nums slashed-zero;

Example

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

<!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

Comparing several features

This example sets each numeric feature on its own paragraph so you can see them side by side (in a font that supports them, such as many Google Fonts faces).

<!DOCTYPE html>
<html>
  <head>
    <title>font-variant-numeric features</title>
    <style>
      .lining   { font-variant-numeric: lining-nums; }
      .oldstyle { font-variant-numeric: oldstyle-nums; }
      .tabular  { font-variant-numeric: tabular-nums; }
      .diagonal { font-variant-numeric: diagonal-fractions; }
      .slashed  { font-variant-numeric: slashed-zero; }
    </style>
  </head>
  <body>
    <p class="lining">lining-nums: 0123456789</p>
    <p class="oldstyle">oldstyle-nums: 0123456789</p>
    <p class="tabular">tabular-nums: 1111 vs 8888</p>
    <p class="diagonal">diagonal-fractions: 1/2 3/4</p>
    <p class="slashed">slashed-zero: 1000 2030</p>
  </body>
</html>

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.

font-variant-numeric is one of several longhands of the font-variant shorthand. The others target different glyph categories:

It is supported from CSS3 onward.

Practice

Practice
What does the CSS font-variant-numeric property do?
What does the CSS font-variant-numeric property do?
Was this page helpful?