Trending
Why Surviving Cancer Still Depends On Where You Live? is trending now How regular exercise, nutrition can prevent cold, by doctors is trending now How stress, banditry contribute to mental health issues —Expert is trending now Secretly Polish: Elżbieta Heweliusz, Poland’s first female astronomer is trending now Researchers in Australia uncover potential source of natural hydrogen is trending now Black-box technologies could undermine confidence in scientific findings is trending now Scientists simulating ant swarms find a 'first mover' can set the colony in motion is trending now Bayer Leverkusen reach ‘clear internal decision’ on selling Jarell Quansah to Arsenal is trending now Ahudiyannem boss rallies stakeholders to save Nigerian football is trending now Man City tight-lipped on Rodri transfer amid Barcelona and Real Madrid link is trending now NFF sets up ‘fact-finding committee’ to probe Falcons’ World Cup failure is trending now BAP Productions’ Dear Kaffy excites London is trending now Why Surviving Cancer Still Depends On Where You Live? is trending now How regular exercise, nutrition can prevent cold, by doctors is trending now How stress, banditry contribute to mental health issues —Expert is trending now Secretly Polish: Elżbieta Heweliusz, Poland’s first female astronomer is trending now Researchers in Australia uncover potential source of natural hydrogen is trending now Black-box technologies could undermine confidence in scientific findings is trending now Scientists simulating ant swarms find a 'first mover' can set the colony in motion is trending now Bayer Leverkusen reach ‘clear internal decision’ on selling Jarell Quansah to Arsenal is trending now Ahudiyannem boss rallies stakeholders to save Nigerian football is trending now Man City tight-lipped on Rodri transfer amid Barcelona and Real Madrid link is trending now NFF sets up ‘fact-finding committee’ to probe Falcons’ World Cup failure is trending now BAP Productions’ Dear Kaffy excites London is trending now
Physical Therapy

One CSS Property That Makes Numbers Look Instantly Better

One CSS Property That Makes Numbers Look Instantly Better

When you’re working with fonts, especially for displaying numbers, there’s something called proportional spacing that can make a huge difference in how your numbers look when they’re animated.

When you’re working with fonts, especially for displaying numbers, there’s something called proportional spacing that can make a huge difference in how your numbers look when they’re animated.

Essentially, most fonts (apart from monospaced fonts) use proportional spacing, which means that each character takes up a different amount of horizontal space. This can lead to numbers looking uneven and misaligned, especially when they’re displayed in a tabular format.

Here’s what it looks like.

proportional vs fixed pitch

This creates issues when numbers change, let’s say in clocks or counters, the text/numbers shifts horizontally, which can be visually jarring. In other words, it will cause a layout shift, which is not a good user experience.

To fix this issue, you can use the font-variant-numeric CSS property (which I recently stumbled upon) with the value tabular-nums.

This will force all the numbers in the font to take up the same amount of horizontal space, creating a more uniform and visually appealing look. Once this property is applied, the numbers behave like monospaced digits, even in proportional fonts.

I’ve created a CodePen demo to show you how it works.

See the Pen Tabular Numbers Demo by Amit Merchant (@amit_merchant) on CodePen.

Now, you might be wondering, what are all the places where this can be useful?

Well, here are a few examples:

  • Clocks and timers
  • Financial tables
  • Analytics dashboards
  • Scoreboards
  • Any place where numbers are displayed in a tabular format

Also, this property is supported in all modern browsers, so you can safely use it in your projects without worrying about compatibility issues.

Read more about the font-variant-numeric property on MDN Web Docs.

View original source →

Related