Typography

Font Variant Numeric

Utilities for controlling the variant of numbers.

Quick reference

Class
Properties
normal-numsfont-variant-numeric: normal;
ordinalfont-variant-numeric: ordinal;
slashed-zerofont-variant-numeric: slashed-zero;
lining-numsfont-variant-numeric: lining-nums;
oldstyle-numsfont-variant-numeric: oldstyle-nums;
proportional-numsfont-variant-numeric: proportional-nums;
tabular-numsfont-variant-numeric: tabular-nums;
diagonal-fractionsfont-variant-numeric: diagonal-fractions;
stacked-fractionsfont-variant-numeric: stacked-fractions;

Basic usage

Applying numeric variants

Use the font-variant-numeric utilities to enable additional glyphs for numbers, fractions, and ordinal markers (in fonts that support them).

These utilities are composable so you can enable multiple font-variant-numeric features by combining multiple classes in your HTML:

  1. <p class="ordinal slashed-zero tabular-nums ...">
  2. 1234567890
  3. </p>

Note that many fonts don’t support these features (stacked fractions support for example is especially rare), so some of these utilities may have no effect depending on the font family you are using.

Ordinal

Use the ordinal utility to enable special glyphs for the ordinal markers.

Font Variant Numeric - 图1

  1. <p class="ordinal ...">1st</p>

Slashed Zero

Use the slashed-zero utility to force a 0 with a slash; this is useful when a clear distinction between O and 0 is needed.

Font Variant Numeric - 图2

  1. <p class="slashed-zero ...">0</p>

Lining figures

Use the lining-nums utility to use the numeric glyphs that are all aligned by their baseline. This corresponds to the lnum OpenType feature. This is the default for most fonts.

Font Variant Numeric - 图3

  1. <p class="lining-nums ...">
  2. 1234567890
  3. </p>

Oldstyle figures

Use the oldstyle-nums utility to use numeric glyphs where some numbers have descenders. This corresponds to the onum OpenType feature.

Font Variant Numeric - 图4

  1. <p class="oldstyle-nums ...">
  2. 1234567890
  3. </p>

Proportional figures

Use the proportional-nums utility to use numeric glyphs that have proportional widths (rather than uniform/tabular). This corresponds to the pnum OpenType feature.

Font Variant Numeric - 图5

  1. <p class="proportional-nums ...">
  2. 12121
  3. </p>
  4. <p class="proportional-nums ...">
  5. 90909
  6. </p>

Tabular figures

Use the tabular-nums utility to use numeric glyphs that have uniform/tabular widths (rather than proportional). This corresponds to the tnum OpenType feature.

Font Variant Numeric - 图6

  1. <p class="tabular-nums ...">
  2. 12121
  3. </p>
  4. <p class="tabular-nums ...">
  5. 90909
  6. </p>

Diagonal fractions

Use the diagonal-fractions utility to replace numbers separated by a slash with common diagonal fractions. This corresponds to the frac OpenType feature.

Font Variant Numeric - 图7

  1. <p class="diagonal-fractions ...">
  2. 1/2 3/4 5/6
  3. </p>

Stacked fractions

Use the stacked-fractions utility to replace numbers separated by a slash with common stacked fractions. This corresponds to the afrc OpenType feature. Very few fonts seem to support this feature — we’ve used Ubuntu Mono here.

Font Variant Numeric - 图8

  1. <p class="stacked-fractions ...">
  2. 1/2 3/4 5/6
  3. </p>

Resetting numeric font variants

Use the normal-nums propery to reset numeric font variants. This is usually useful for resetting a font feature at a particular breakpoint:

  1. <p class="slashed-zero tabular-nums md:normal-nums ...">
  2. 12345
  3. </p>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:tabular-nums to only apply the tabular-nums utility on hover.

  1. <p class="proportional-nums hover:tabular-nums">
  2. <!-- ... -->
  3. </p>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:tabular-nums to apply the tabular-nums utility at only medium screen sizes and above.

  1. <p class="proportional-nums md:tabular-nums">
  2. <!-- ... -->
  3. </p>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.