font-variant-numeric

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 concern is that there is a limited number of fonts that can maximize the use of 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

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

Example of the font-variant-numeric property:

<!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">952321313500</p>
  </body>
</html>

Result

Values

Values

ValueDescription
normalThe use of alternate glyphs are not enabled.
<numeric-figure-values>Controls the figures which are used for numbers.
<numeric-spacing-values>Controls the sizing of figures which is used for numbers.
<numeric-fraction-values>Controls the glyphs which are used for fractions.
ordinalForces the use of special glyphs for the ordinal markers, like 1st, 2nd, 3rd. It corresponds to the OpenType values ordn.
slashed-zeroForces the use of a 0 with a slash. This is needed when O and 0 are not differentiated. It corresponds to the OpenType values zero.
initialIt makes the property use its default value.
inheritIt inherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部