Font-variant-numeric - CSS Property
Summary of characteristics of the font-variant-numeric property
normal | ordinal | slashed-zero | lining-nums | oldstyle-nums | proportional-nums | tabular-nums | diagonal-fractions | stacked-fractionsnormalDiscrè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.Syntax diagram of font-variant-numeric.
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.
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
ordinalvalue 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
ordinalvalue corresponds tofont-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
monospacefont: 0. - Use the character with the hexadecimal code
D8(216 in decimal): Ø. - Use the HTML entity
Ø: Ø.
The value
slashed-zerocorresponds tofont-feature-settings:'zero'.1000 KO - Use the zero character from the generic
- 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 foroldstyle-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-numscorresponds tofont-feature-settings:'lnum'.
The valueoldstyle-numscorresponds tofont-feature-settings:'onum'.0 1 2 3 4 5 6 7 8 9font-variant-numeric:lining-nums;0 1 2 3 4 5 6 7 8 9font-variant-numeric:oldstyle-nums; - font-variant-numeric: proportional-nums; font-variant-numeric: tabular-nums;
These two values are mutually exclusive.
proportional-numsrequests that the width of each digit be adjusted based on its shape (the1is narrower than the8). The text looks nicer, but numbers listed in a column don't line up vertically.tabular-numsrequires 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-numscorresponds tofont-feature-settings:'pnum'.
The valuetabular-numscorresponds tofont-feature-settings:'tnum'.111 222 3131
222 111 1313font-variant-numeric:proportional-nums;111 222 3131
222 111 1313font-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-fractionsmeans 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-fractionscorresponds tofont-feature-settings:'afrc'.
The valuediagonal-fractionscorresponds tofont-feature-settings:'frac'.
font-variant-numeric:stacked-fractions;
(simulation)1/1000 1/2font-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.
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).

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.

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).

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.

// 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.

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
monospacefont displays slashed zeros no matter the value offont-variant-numeric. Handling theordinalvalue 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.
| Font | Ordinal | Slashed zeros | Old-style | Tabular | Fractions |
|---|---|---|---|---|---|
serif | OK | OK | OK | ||
sans-serif | OK | OK | OK | ||
monospace | OK | OK | OK | ||
cursive | OK | OK | |||
Fira Sans | OK | OK |
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.
font-variant-numeric property defines how numbers are displayed.font-variant-numericproperty
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 propertiesfont-...allow choosing the final appearance of the characters.
Fonts can be located on the user's computer or downloaded.Regardingfont-variant-numeric:
First definition of thefont-variant-numericproperty.July 21, 1997Working Draft.October 03, 2013Candidate Recommendation.August 14, 2018Proposed for recommendation.September 20, 2018Recommendation . -
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.
Regardingfont-variant-numeric:
No change to thefont-variant-numericproperty.July 11, 2017Working Draft. -
CSS Fonts Module Level 5
June 29, 2021Working Draft.
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:






em, ex, etc.








Functions:

At-rules:



Descriptors :

@font-face. Sets the height of the characters above the baseline.

@font-face. Sets the height of the characters below the baseline.

@font-face. Determines how the browser behaves when faced with fonts that take a long time to load.

@font-face. Sets the line spacing of the font.

@font-face. Defines the range of character codes to be downloaded into a font.


