Skip to main content
Login

Sign in to access your account

Numbers - National Design System

A class that formats a number with separators, a currency symbol or a unit, and an attribute that counts up to a number when it scrolls into view

Overview

Numbers is a class and an attribute. nds-number-format formats the number in an element’s text, and can add a currency symbol or a unit. data-counter counts up to a number.

Pick another component when:

Markup

Preview
3240000
<span class="nds-number-format">3240000</span>

Behavior

Counter Animation

A counter counts from data-counter-start to the data-counter value when half of it is in view. It runs once, and then the script sets data-animated on it. A user who asks the system for reduced motion sees the end value at once. The counter adds separators itself, so it needs nds-number-format only for a currency or a unit.

The counter reads data-counter when the count starts, not when the page loads. A value from a server works: set data-counter when the reply arrives, and a counter not yet in view counts to it with no other call. A counter that already ran keeps its old value: remove data-animated, then call NDS.Numbers.init().

Currency Symbol

data-currency adds the currency symbol beside the number. The symbol sits before the number in English and after it in Arabic. SAR draws the Riyal sign as an icon in the text color. The other codes add their Unicode symbol.

Unit

data-unit adds its text after the number, in English and in Arabic. CSS draws the unit, so it stays when a script changes the number, as the Slider does. After the change, call NDS.Numbers.format(el) to add the separators.

Built-in Features

  • Automatic Start

    The loader starts Numbers on any page that has nds-number-format or data-counter. You write no script.

  • Locale Separators

    Separators follow the lang of the page, and digits are always Latin (0 to 9), whatever the language of the browser. Text before and after the number, the sign and the decimals stay.

  • Child Elements Kept

    Only the first text in the element that holds a digit changes. Icons and other child elements stay in place.

  • Safe to Run Again

    The script remembers the text it wrote and reads the original number again. A number formatted twice reads the same as one formatted once, in every language.

  • Code Blocks Skipped

    A number inside <code> stays as written.

Best Practices

  • Write the number in plain digits, with commas or no separators. It shows before the script runs. The script cannot read other separators, such as 3.240.000.
  • Write 0 as a counter’s text. It shows until the count starts.
  • Write the number with the decimals you want shown. 1250.50 shows as 1,250.50, and a counter with data-counter="98.6" counts with one decimal.
  • Use data-currency, not a symbol in the text. See Currency Symbol.
  • A screen reader does not read the SAR icon. Where the currency matters, add it as hidden text after the number: <span class="nds-number-format" data-currency="SAR">1250 <span class="nds-sr-only">riyals</span></span>.
  • Use data-unit for a unit on a number that a script changes. For a fixed suffix, write it in the text, such as 98.5%.
  • Use a counter for a few headline figures, such as the statistics on a home page or KPI cards. A value loaded once from a server is fine. Do not use it for a value that keeps updating or that the user changes: it runs once.
  • Keep data-counter-duration between 800 and 2000 ms. A shorter count is too fast to see, and a longer one delays the figure.
  • For a free price, write the label, such as “Free” or “مجاني”, with no data-currency.
  • Give a counter with a currency or a unit the nds-number-format class too: <span class="nds-number-format" data-currency="SAR" data-counter="1250">0</span>.
  • Put a counter in a statistic card for a headline number with a label: a centered card, with the counter on its nds-card-number.

API

Data Attributes

Attribute Element Effect
data-currency .nds-number-format Adds the currency symbol: SAR, USD, EUR, GBP, JPY, CNY, INR, KRW or TRY. Any other value adds nothing
data-unit .nds-number-format Adds its text after the number as a unit. Do not combine it with data-currency
data-counter any element Makes the element a counter. Its value is the end value. Text before and after the number stays: $75,000, 98.6%, 1.5M. Empty, the counter counts to the number in its own text
data-counter-start [data-counter] The start value. Default 0
data-counter-duration [data-counter] The length of the count in milliseconds. Default 1000
data-animated [data-counter] The script sets it to true when the count ends, and never removes it. A counter with it does not run. To run a counter again, remove it, then call NDS.Numbers.init(). The counter starts from data-counter-start again

CSS Custom Properties

Property Default Controls
--number-icon-size 1em The size of the SAR icon and of an .nds-icon child. Set it on .nds-number-format or on a parent

JavaScript

The NDS.Numbers script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.

Method Effect
NDS.Numbers.init() Formats every number and gets every counter ready to count when it scrolls into view. The loader calls it. Call it after you add numbers or counters to the page
NDS.Numbers.format(el) Formats one .nds-number-format element
NDS.Numbers.formatAll() Formats every .nds-number-format on the page
NDS.Numbers.initCounters() Gets every counter ready to count when it scrolls into view. It skips a counter with data-animated

Numbers fires no events. To format a number in your own script, use NDS.formatNumber(n, options): it uses the lang of the page and Latin digits. The full API is in the banner of _js/nds-numbers.js.

var total = document.querySelector('#order-total'); total.textContent = '18450'; NDS.Numbers.format(total); // After you add counters to the page NDS.Numbers.init();
Last Modified Date: 01/11/2026 - 05:15 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks