Front-end education for the real world. Since 2018.





Control changing numbers with font variant numeric

Andy Bell

Topic: CSS

Say you’ve got a countdown timer. The UI can jump around, depending on what sort of font you’re using, which can be a pain.

One option is to use monospaced fonts, but another smart approach is using font variant properties.

Code language
css

.my-tabular-element {
	font-variant-numeric: tabular-nums;
}

As long as your font supports, it you can totally transform how numbers render in your chosen font. Some CDN fonts, like Google Fonts, strip this support out though, so remember that if it’s not working for you.

Enjoyed this article? You can support us by leaving a tip via Open Collective


Newsletter