Font-variant-numeric - CSS Property

font-variant-numeric

Summary of characteristics of the font-variant-numeric property

Quick description
Defines how evolved numbers are displayed: fractions, numbers, etc.
Status
Standard
Predefined values
normal | ordinal | slashed-zero | lining-nums | oldstyle-nums | proportional-nums | tabular-nums | diagonal-fractions | stacked-fractions
Percentages
Not applicable.
Initial value
normal
Inherited by default
Yes.
Discrète: during an animation, the font-variant-numeric property passes from one value to another without transition.
Per grammar: serialization in the order of syntax. Values can be entered in any order.
W3C Module
CSS Fonts Module
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: REC (Recommendation)

Syntax diagram of font-variant-numeric.

Font-variant-numeric property - Syntax diagramSyntax diagram of the font-variant-numeric CSS property. Enables or disables the different forms for numeric characters. normal normal lining-nums lining-nums oldstyle-nums oldstyle-nums proportional-nums proportional-nums tabular-nums tabular-nums diagonal-fractions diagonal-fractions stacked-fractions stacked-fractions ordinal ordinal slashed-zero slashed-zerofont-variant-numeric:;font-variant-numeric:;
Syntax diagram of the font-variant-numeric property.
The links in the diagram provide more details about the values.
Download the diagram.

Description of the font-variant-numeric property.

font-variant-numeric defines the advanced display settings for numbers, like how fractions, ordinals, etc. are presented. This property offers a lot of features but also depends heavily on the OTF font used.
It is possible, for example, to request the display of numbers in their ordinal form or in their fractional form.

The 1st runner arrived with only 1/2 second ahead.

For a more complete presentation of the possibilities offered by OTF fonts and their use with low-level syntax, refer to the property font-feature-settings .
Also check out the shorthand property font-variant.

Values for font-variant-numeric.

  • font-variant-numeric: normal;

    Default value. The numbers are shown with their standard glyph, without any special formatting.

    0 1 2 3 4 5 6 7 8 9
  • font-variant-numeric: ordinal;

    Ordinal numbers, like 1st, 3rd, as well as symbols like No, etc., are replaced by the characters 1st, 3rd, No, etc.

    You can get a similar effect with the HTML sup tag, but you need to apply this tag specifically to the part of the number that should be superscript, whereas the ordinal value can be applied to the whole text, and the detection of the characters to be superscripted is automatic.

    French ordinal characters like 2ème aren't supported by any font we know of, because of the accent.

    The ordinal value corresponds to font-feature-settings:'ordn'.

    1st 2nd 3rd
    4th 5e 6a No
  • font-variant-numeric: slashed-zero;

    Zeros are crossed out (Ø). It's useful when you need to avoid any confusion between the number 0 and the letter O.

    This feature isn't that commonly known, but there are several other ways to get a slashed zero:

    • Use the zero character from the generic monospace font: 0.
    • Use the character with the hexadecimal code D8 (216 in decimal): Ø.
    • Use the HTML entity Ø: Ø.

    The value slashed-zero corresponds to font-feature-settings:'zero'.

    1000 KO
  • font-variant-numeric: lining-nums; font-variant-numeric: oldstyle-nums;

    These two values cannot appear together in the syntax. They indicate, for lining-nums, that the numbers all have the same height and are all positioned on the same baseline, and for oldstyle-nums, that the numbers are positioned at different heights on the line and may also have different heights, giving a slightly retro effect.

    The value lining-nums corresponds to font-feature-settings:'lnum'.
    The value oldstyle-nums corresponds to font-feature-settings:'onum'.

    0 1 2 3 4 5 6 7 8 9
    font-variant-numeric:lining-nums;
    0 1 2 3 4 5 6 7 8 9
    font-variant-numeric:oldstyle-nums;
  • font-variant-numeric: proportional-nums; font-variant-numeric: tabular-nums;

    These two values are mutually exclusive.

    proportional-nums requests that the width of each digit be adjusted based on its shape (the 1 is narrower than the 8). The text looks nicer, but numbers listed in a column don't line up vertically.

    tabular-nums requires that the width of each digit is the same. This option is useful when numbers are shown in a column and you want the digits to line up vertically.

    The value proportional-nums corresponds to font-feature-settings:'pnum'.
    The value tabular-nums corresponds to font-feature-settings:'tnum'.

    111 222 3131
    222 111 1313
    font-variant-numeric:proportional-nums;
    111 222 3131
    222 111 1313
    font-variant-numeric:tabular-nums;
  • font-variant-numeric: diagonal-fractions; font-variant-numeric: stacked-fractions;

    These two values can't appear at the same time in the syntax.

    diagonal-fractions means that two numbers separated by a slash character (/) are displayed as a fraction, with a diagonal line between them.

    As for stacked-fractions, it means that two numbers separated by a slash (/) are displayed as a fraction, with a horizontal line. This feature is recognized by few fonts.

    The value stacked-fractions corresponds to font-feature-settings:'afrc'.
    The value diagonal-fractions corresponds to font-feature-settings:'frac'.

    Exemple pour font-variant-numeric:stacked-fractions
    font-variant-numeric:stacked-fractions;
    (simulation)
    1/1000   1/2
    font-variant-numeric:diagonal-fractions;
  • font-variant-numeric: initial; (normal) font-variant-numeric: inherit; font-variant-numeric: revert; font-variant-numeric: revert-layer; font-variant-numeric: revert-rule; font-variant-numeric: unset;

    Links to the presentation of these different values: initial, inherit, revert, revert-layer, revert-rule, unset.

Animation of the font-variant-numeric property.

The example below shows that animating font-variant-numeric is possible, even if its usefulness is limited.

Note: the property font-variant-numeric is applied to the words No and 2nd. Applying it to the whole sentence gives a weird result.
Besides, we had to write 2nd without an accent, because the accent messes up the functionality.

The bib No28
came in 2nd.

Access the font-variant-numeric property via a program

Changing the value of font-variant-numeric with Javascript.

You can see that JavaScript offers a syntax with the typical CSS notation, in kebab-case (a dash to separate words), and another syntax with camel-case notation (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['font-variant-numeric'] = 'lining-nums'; // or let el = document.getElementById('id'); el.style.fontVariantNumeric = 'lining-nums';

Retrieving the value of font-variant-numeric with JavaScript.

The property must have been applied directly to the element itself via its style attribute, not through a CSS selector.

Javascript
let el = document.getElementById('id'); let value = el.style['font-variant-numeric']; // or let el = document.getElementById('id'); let value = el.style.fontVariantNumeric;

Retrieving the computed value of font-variant-numeric.

The computed value is the one that results from the cascade of inheritances. If not, the calculated value is the initial value of the property (normal in the case of font-variant-numeric).

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('font-variant-numeric');

Reading and changing the value of font-variant-numeric with JQuery.

JQuery

// Read the value:
$('#id').prop('font-variant-numeric');
// Write the value:
$('#id').prop('font-variant-numeric', 'lining-nums');
$('#id').prop('{font-variant-numeric': 'lining-nums'});

Retrieving the computed value of font-variant-numeric with JQuery.

JQuery
let value = $('#id').css('font-variant-numeric');

Test by your self.

The buttons below apply the entered value to the font-variant-numeric property and then show either the value as it was applied or the computed value. The second option lets you see how the value of font-variant-numeric is stored (serialized). In the case of font-variant-numeric, the calculated value is the same as the entered value because this property only accepts predefined values. However, if you enter an incorrect value or two incompatible values, the assigned value will be empty while the calculated value will be the property's initial value (normal for font-variant-numeric).

Simulator.

The simulator below lets you test different values for the property font-variant-numeric with several fonts. You can see that the result is highly dependent on the font:

  • The monospace font displays slashed zeros no matter the value of font-variant-numeric. Handling the ordinal value seems correct in this very simple example, but it should be applied very specifically, word by word.
  • The treatment of fractions is different from one font to another.
FontOrdinalSlashed
zeros
Old-styleTabularFractions
serif OKOKOK
sans-serif OKOKOK
monospace OKOKOK
cursive OKOK
Fira Sans OKOK

Police :

font-variant-numeric :

1er   1st   2ème   No   9a
1200   458   1114
8540   710   8437
3/4   240/1000   7/22

Browsers compatibility with font-variant-numeric.

The font-variant-numeric property brings new ways to display numbers. Support is now good on most browsers. Keep in mind, though, that all these features mostly depend on the font you’re using.

Column 1
Support for the font-variant-numeric property defines how numbers are displayed.
1
font-variant-numeric
property
Estimated overall support.
97%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Safari

Safari sur IOS

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

Historic of the font-variant-numeric property.

  • CSS Fonts Module Level 3

    This specification concerns fonts. A font contains the visual representation of characters. In its simplest form, it is just a matter of associating character codes with their shapes.
    Within a typeface family, the shapes are defined but can vary in stroke thickness, slant, width, etc. The CSS properties font-... allow choosing the final appearance of the characters.
    Fonts can be located on the user's computer or downloaded.

    Regarding font-variant-numeric:
    First definition of the font-variant-numeric property.
    WD
    July 21, 1997
    Working Draft.
    CR
    October 03, 2013
    Candidate Recommendation.
    PR
    August 14, 2018
    Proposed for recommendation.
    REC
    September 20, 2018
    Recommendation .
  • CSS Fonts Module Level 4

    This level 4 of the specification on fonts reprises what is defined in level 3. It adds the possibility to define what happens when a font takes a long time to load or is missing. It also adds support for colored fonts and clarifies many points still poorly defined in level 3.

    Regarding font-variant-numeric:
    No change to the font-variant-numeric property.
    WD
    July 11, 2017
    Working Draft.
    CR
    PR
    REC
  • CSS Fonts Module Level 5

    WD
    June 29, 2021
    Working Draft.
    CR
    PR
    REC

See also about fonts.

The CSS Fonts Module specification covers everything related to fonts, typography, making the most of modern font formats, font downloads, and so on.

Properties:

font
Langue française
Shorthand to set most properties for fonts.
✗
font-effect
Langue française
Allows you to apply some effects to the text: relief, border...
font-family
Selects a font from those that are available or downloaded.
⚠
font-feature-settings
Langue française
Permet d’exploiter les fonctionnalités spécifiques des polices de caractères OTF, WOFF, etc.
font-kerning
Adjusting the kerning between characters.
⚠
font-language-override
Langue française
Defines the language to be considered when choosing characters.
⚠
font-optical-sizing
Langue française
Optimizes the shape of characters based on their size.
font-palette
Langue française
Defines the color palette that can be used for colored fonts.
font-size
Adjusts the font size, which also impacts units like em, ex, etc.
font-size-adjust
Langue française
Definition of the aspect factor of the font.
✗
font-smooth
Langue française
Defines whether and which smoothing algorithm should be used.
font-stretch
Langue française
Changes the stretching or compression of characters.
font-style
Langue française
Selects the italic or oblique font styles.
font-synthesis
Allows or disallows calculation of missing styles in the typeface.
⚠
font-synthesis-position
Langue française
Whether or not allows the browser to synthesize characters in superscript or subscript.
font-synthesis-small-caps
Langue française
Whether or not allows the browser to calculate the glyphs of characters in small caps.
font-synthesis-style
Langue française
Defines whether the browser is allowed to synthesize italic forms of characters.
font-synthesis-weight
Langue française
Defines whether or not the browser can calculate the bold glyph.
font-variant
Shorthand to define advanced typographic attributes: ligatures, character substitution, etc.
font-variant-alternates
Defines character substitution (OTF, WOFF fonts).
font-variant-caps
Applies character capitalization.
font-variant-east-asian
Typography specific to Chinese or Japanese characters.
⚠
font-variant-emoji
Choose between an emoji or text presentation.
font-variant-ligatures
Enables or disables character ligation.
Font-variant-numeric
Defines how evolved numbers are displayed: fractions, numbers, etc.
⚠
font-variant-position
Superscript or subscript of characters.
font-variation-settings
Provides access to the stylistic possibilities of OTF fonts.
font-weight
Selects a weight for the characters.
font-width
Langue française
Synonymous with font-stretch (character width/enlargement).

Functions:

⚠
palette-mix()
Langue française
Establish the mixture of two color palettes from two different typefaces.

At-rules:

@font-face
Langue française
Defines all settings for a downloadable font.
⚠
@font-feature-values
Langue française
Defines the typographic variations to use.
@font-palette-values
Langue française
Defines a color palette that can then be applied to a font.

Descriptors :

ascent-override
Langue française
Descriptor for @font-face. Sets the height of the characters above the baseline.
descent-override
Langue française
Descriptor for @font-face. Sets the height of the characters below the baseline.
⚠
font-display
Langue française
Descriptor for @font-face. Determines how the browser behaves when faced with fonts that take a long time to load.
line-gap-override
Langue française
Descriptor for @font-face. Sets the line spacing of the font.
src
Langue française
Defines the source of a font file to download, or an image to display.
unicode-range
Langue française
Descriptor for @font-face. Defines the range of character codes to be downloaded into a font.