Skip to content

In the page

What assistive tech hears, what reduced motion gets, how to style it, how it's drawn on a server, and what it costs.

@cesarvenzac/rollv1.1.0

Read once

Assistive tech hears the value in words, once, and never the drawing that moves, which is hidden from it. The words are the value's text, a node's aria-label, title or text, or label where you give one: give an icon one.

Reduced motion

Under prefers-reduced-motion, nothing moves: the new character fades in where it stands, in less than a fifth of a second, a count goes straight to its number, and a trend still tints. reducedMotion says otherwise: true to fade whatever the system says, false to move.

Styling

It's text: set its font, size, colour and line height on the element, and they hold while it rolls. Kerning and ligatures are off inside it, so a character is as wide alone as among the others and nothing shifts as it turns into cells and back.

A value that counts draws tabular figures, every digit one width; any other keeps the font's own, whose widths Roll eases as they change. tabular says otherwise either way. Tabular figures suit a number that changes while it's watched (a price, a clock, a column of numbers); the font's own, a large figure that changes now and then.

A symbol fades as it leaves its line, and symbols are spaced so that what hangs past a line, a g's tail, an accent, a line set tight, never peeks once a turn lands. A character is one as you read it: an é written as an e and an accent, a flag, a family of emoji.

On a server

React's Roll draws its value as plain text on a server, a number as format writes it and an element as React renders it, laid out as the browser will draw it, so nothing moves as the page hydrates. <roll-text> takes up the text written inside it before it's defined.

At rest

At rest the value is one text node, as crisp as any text, selected and copied as text, costing nothing; it goes back to plain text without moving the text after it. Measured in em against a ruler under the same transforms, it rolls true in a scaled sheet or a page zoomed to be filmed.

Cost

About 9 kB minified and gzipped for roll, 10 kB with every entry. Every roller on the page changes in one batch: all write, all read in one layout, all animate, so a table of numbers changing at once lays out once, not once a number. Starting a turn takes about 2 milliseconds for a number, 12 for twenty changing at once and 80 for two hundred, in headless Chromium on one core of a 2.1 GHz server.

Springs play as a CSS linear() easing between two keyframes, where the browser has one (Chrome 113, Safari 17.2, Firefox 112), and as a keyframe a frame elsewhere. Any browser with the Web Animations API rolls.