Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

counter

TextAlso inMaps and dataScroll scenes

@dioramajs/text/counterSource

Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.

View as Markdown
On this page

Open water season 2026

12,480 swimmers

crossed the bay with a club coach since the first of May.

Live preview needs WebGPU or WebGL 2. A swim club's season stat whose digits turn on odometer drums from 0 up to 12,480 and fold back into the text.

This example failed to draw.

When a number such as 12,480 or $4.2M scrolls into view, each of its digits sits on a drum that turns in 3D: digits curve over the top and bottom of the drum, foreshortened and darker as they turn away, with a soft sheen and seams between the drums. The value counts up from 0 like a mechanical odometer, the last drum overshooting its digit and settling back. The slot style spins deeper reels behind window frames, blurred while they spin, and lands them one by one from right to left with a bounce; the flip style drops the top half of each card about its hinge towards the viewer until the digit lands. The text around the number and its separators stay flat. When the digits land, the drums or cards fold back into the page and the element is its own text again.

Every switch and slider counts it again.

Params of counter
style

odometer turns flush drums in a row, for stats sections.

trigger

view counts once when the number enters.

Usage

Put it on a heading, paragraph or span holding one number, with any text before and after it, such as $4.2M, 99.9% or 12,480 swimmers. start() registers counter, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add counter
<div class="cn-stat">
<p class="cn-kicker">Open water season 2026</p>
<p class="cn-number" data-dio="counter">
12,480
<span>swimmers</span>
</p>
<p class="cn-note">crossed the bay with a club coach since the first of May.</p>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.cn-number', 'counter', {
style: 'odometer',
trigger: 'view',
duration: 2,
from: 0,
stagger: 0.12,
delay: 0,
threshold: 0.3,
})
import { start } from '@dioramajs/diorama'
import counter from '@dioramajs/text/counter'
const app = start()
app.attach('.cn-number', counter({
style: 'odometer',
trigger: 'view',
duration: 2,
from: 0,
stagger: 0.12,
delay: 0,
threshold: 0.3,
}))

Page transitions

Entering a page the number counts up from its start value; leaving, it counts back down to it. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'odometer' | 'slot' | 'flip''odometer'
  • odometer turns flush drums in a row, for stats sections.
  • slot spins deep reels behind window frames and lands them right to left, for totals and prices.
  • flip drops flip cards through the digits, for dashboards and scores.
triggerrebuildsdata-dio-trigger'view' | 'scroll''view'
  • view counts once when the number enters.
  • scroll ties the count to the scroll, both ways.
durationdata-dio-durationnumber0.3 to 6 s2Time of the count; with slot and flip, until the last digit lands.
fromdata-dio-fromnumber0 to 1000000Value the count starts from, at most what the digits of the number can hold.
staggerdata-dio-staggernumber0 to 0.5 s0.12Delay between neighboring digits landing, for slot and flip.
delaydata-dio-delaynumber0 to 3 s0Wait after the trigger, for a row of stats.
thresholddata-dio-thresholdnumber0 to 10.3Share of the element height in view, above the bottom tenth, before it counts.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads height, presence, progress, size, width, x and y . Draws only while something on it moves, then stops. Only while the digits turn and fold back, and with the scroll trigger while scrolling; none at rest. How a frame is decided.

Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the number is shown as it is, and the engine does not load for it.

Runs on every device. The same as with a mouse: nothing reads the pointer.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { counter: { reducedMotion: 'static' } } })

Cost and quality

Download
12.9 KB min+gzip the first time a page uses it
GPU
A strip of 24 quads per digit with ten texture reads per pixel for the motion blur, a quad per letter around the number.
Memory
A canvas of the text at twice its CSS size and a small sheet of the digits, kept while the element lives.
Frames
Idle at rest

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
lowThe text and the digits are rastered at 1 device pixel per CSS pixel instead of 2.

Recipes

A row of stats that count in turn

Give each stat its own element and a growing delay, so the numbers land one after another instead of all at once. Each number can take its own style. Scroll down to this example to see it count.

  • 312

    clubs on the platform
  • $4.2M

    raised for open water safety
  • 99.9%

    of sessions booked online

Live preview needs WebGPU or WebGL 2. Three stats of a swim club platform that count up in turn on drums, slot reels and flip cards.

This example failed to draw.

<ul class="cn-row">
<li>
<p data-dio="counter">312</p>
<span>clubs on the platform</span>
</li>
<li>
<p
data-dio="counter"
data-dio-style="slot"
data-dio-delay="0.25"
>$4.2M</p>
<span>raised for open water safety</span>
</li>
<li>
<p
data-dio="counter"
data-dio-style="flip"
data-dio-delay="0.5"
>99.9%</p>
<span>of sessions booked online</span>
</li>
</ul>

A total on slot machine reels

style="slot" spins every digit on a deep reel behind a window frame and lands them from right to left, each with a bounce. A longer stagger makes the wait for the last reel part of the show, which suits fundraising totals and prize pools.

<p
class="total"
data-dio="counter"
data-dio-style="slot"
data-dio-stagger="0.25"
data-dio-duration="1.6"
>$4,250,000</p>

A year that follows the scroll

With data-dio-trigger="scroll" the count follows the scroll position both ways, from from when the number enters to its value when it reaches the middle of the viewport. On a company timeline it turns the years as the visitor reads.

<p
class="year"
data-dio="counter"
data-dio-trigger="scroll"
data-dio-from="1998"
>2026</p>

Notes

The element holds one number, with any text before and after it: $4.2M, 99.9%, 12,480 swimmers or Over 1,200 teams. Only the first number counts; put two stats in two elements. The number keeps the way it is written: its group separators, decimals and leading zeros, as in 1.204.500 or 1 024. A lone point or comma before three digits, as in 3.142, is read with the decimal separator of the page language, so set lang on the page or the element; without one, 12,480 is twelve thousand. A minus sign stays in front as text.

The DOM text never changes, so screen readers, search engines and find in page always see the final value. The drums, reels and cards are drawn only while the digits turn; when they land they fold back into the page and the element is real, selectable text again. Under reduced motion the effect is off and the number shows at once.

Each style draws its parts from the text color and the background behind the element: dark drums on a dark page, light ones on a light page. While they turn, the drums reach about a third of an em above and below the digits, so give the number a line height of 1.3 or some room around it. While the number counts, the element itself is hidden behind its copy, its own background too: put a card’s background on a parent.

from cannot hold more digits than the number, so from="900" works for 1,024 but not for 24. A number on screen when the page opens is hidden until the effect is ready and then counts, as with text-reveal; with the scroll trigger it stays as it is instead.

The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does. An element with any of them keeps its number as it is, and a warning in development names the reason. style and trigger rebuild the effect when they change.