Playground

Number ticker

Count up to a number when it scrolls into view. Shows the final value at once for reduced motion.

  • Built on native elements
  • Screen readers get the final number from an sr-only copy; the animated frames are aria-hidden.
  • With prefers-reduced-motion the final number shows immediately and nothing animates.
  • Styles in one file: number-ticker.css

Import

import '@monoline/css';
import {NumberTicker} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add number-ticker

Usage

import {NumberTicker} from '@monoline/react';

<p style={{fontFamily: 'var(--font-display)', fontSize: 'var(--display-sm)'}}>
  <NumberTicker value={12840} />
</p>

Examples

Count up

Starts when it scrolls into view.

Decimals and units

Props

NumberTickerProps

PropTypeDefaultDescription
value requirednumber–The number to count to. Screen readers get this, never the frames in between.
fromnumber0Where the count starts. Default 0.
durationnumber1500Milliseconds for the count. Default 1500.
decimalsnumber0Digits after the decimal point. Default 0.
format((n: number) => string)–Custom formatting, for currency or units. Overrides `decimals`.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

This component sets no state attributes.

CSS classes

ClassStylesheet
.number-tickernumber-ticker.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.number-ticker {
  border-color: var(--accent);
}

Accessibility

  • Screen readers get the final number from an sr-only copy; the animated frames are aria-hidden.
  • With prefers-reduced-motion the final number shows immediately and nothing animates.