Numbers Formatting & Counter - National Design System

Utilities for formatting large numbers with locale-aware separators, animating counters on scroll, and appending currency symbols automatically.

Number Formatting

Add nds-number-format to any element containing a number. The formatter applies locale-appropriate thousand separators on page load, preserving surrounding text, signs, and decimals.

Thousand Separators
3240000 1850 42850.75 +2500 -340

Counter Animation

Add nds-counter-value and set data-target to the final value. The counter animates from zero when the element scrolls into view. Combine with nds-number-format to apply thousand separators to the final value.

Basic Counter
0

Government Services

0

Citizens Served

0

Satisfaction Rate

Counter Options
0

Custom start — data-start="5000"

0

Custom duration — data-duration="3000"

0

No decimals — data-decimals="0"

Currency

Add data-currency to any nds-number-format element to append the currency symbol automatically. SAR renders as the official Saudi Riyal SVG icon; other currencies use their Unicode symbols.

Static Amounts
450000 99999.99 75000 Free
Animated Amounts
0

Annual Budget

0

Revenue

0

Savings

Built-in Features

Auto-initialization

Both number formatting and counter animations activate automatically on page load with no extra JavaScript required.

Locale-aware Formatting

Numbers are formatted with thousand separators based on the user's browser locale, preserving any surrounding text, signs, or suffixes.

Currency Symbols

Add data-currency for automatic currency symbols including SAR (Saudi Riyal icon), USD, EUR, GBP, JPY, CNY, INR, KRW, and TRY.

Scroll-triggered Counters

Counter animations begin when the element scrolls into view, with configurable start value, target, duration, and decimal precision.

Reduced Motion Support

Users who prefer reduced motion see the final counter value immediately with no animation, respecting the prefers-reduced-motion media query.

Programmatic Control

Call NDS.Numbers.reinit() after dynamically adding numbers to format and animate new elements.

Usage Guidelines

Best Practices

  • Use nds-number-format on any element displaying a large number (thousands or more) to improve readability with locale-appropriate separators
  • Use nds-counter-value for hero statistics, KPI dashboards, and landing page metrics where counting animation draws attention to key figures
  • Combine both classes (nds-counter-value nds-number-format) so that the final counter value also receives thousand separators
  • Do not use counter animations for frequently updated live data or values that change on user interaction — counters are designed to play once on scroll
  • Prefer data-currency over manually adding currency symbols; the attribute handles RTL/LTR symbol placement automatically
  • Set data-duration between 800 and 2000 ms — shorter durations feel abrupt, longer ones delay comprehension
  • Use data-decimals to control precision; omit it to auto-detect from the target value, or set it to 0 for whole numbers
  • Place the raw number as the element's text content — the formatter parses it on load, so the number remains visible even before JavaScript runs
  • Pair counters with statistic cards for a polished dashboard layout

Data Attributes

Attribute Default Description
data-currency none Set on .nds-number-format. Supported values: SAR, USD, EUR, GBP, JPY, CNY, INR, KRW, TRY
data-free absent Set on .nds-number-format to suppress the currency symbol. Pair with a text label such as "Free" or "مجاني" for zero-price items.
data-target Element text Set on .nds-counter-value. Target number to count to. A suffix in the value (e.g. "98.5%") is preserved and appended to the animated number.
data-start 0 Starting number for the counter animation
data-duration 1000 Animation duration in milliseconds
data-decimals auto Force specific decimal places. When not set, matches decimals in data-target. Set to 0 to display whole numbers only.

CSS Custom Properties

Property Default Description
--number-icon-size 1em Size of currency icons and child .nds-icon elements inside a formatted number

JavaScript API

The NDS.Numbers module initializes automatically on page load. Call NDS.Numbers.reinit() after dynamically adding elements to the page.

// ── Format numbers on the page ────────────────────── // Finds all .nds-number-format elements and applies // locale-appropriate thousand separators NDS.Numbers.formatNumbers(); // ── Start counter animations ───────────────────────── // Observes all .nds-counter-value elements and animates // them when they scroll into view NDS.Numbers.setupCounterAnimations(); // ── Re-initialize everything ───────────────────────── // Runs both formatNumbers() and setupCounterAnimations() // Call after dynamically adding new number elements NDS.Numbers.reinit();
Was this page useful?
60% of users said Yes from 2843 Feedbacks