Code Block
Code to read and copy: file name, line numbers, highlighted lines and a monochrome syntax in weight and light. Copy rolls to Copied; a terminal copies its commands only.
View codeA figure that rolls into place like an odometer when it comes into view: digits on the right spin more and land last, a zero takes a full turn. Readable without the script.
With your AI
Say it to your AI. It gets the exact code below, not its best guess, and knows where it goes.
Animate my key figures with the Kodza Counter.
claude mcp add -t http kodza https://kodza.dev/api/mcp
<div class="kodza-counter">
<p class="kodza-counter__value">12,480</p>
<p class="kodza-counter__label">components copied this month</p>
</div>
<div class="kodza-counter">
<p class="kodza-counter__value">99.9%</p>
<p class="kodza-counter__label">uptime, on a good day</p>
</div>
<div class="kodza-counter">
<p class="kodza-counter__value">0</p>
<p class="kodza-counter__label">dependencies. Still.</p>
</div>
/* Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license */
/* Kodza — Counter
A figure that rolls into place like an odometer when it comes into view: every digit spins
from 0, the ones on the right spin more and land last; a zero takes one full turn for the
fun of it. Write the final figure in the HTML (it stays readable without the script, and
for search engines); separators, decimals and signs stay put.
Everything is tuned with the --kz-counter-* variables. */
.kodza-counter {
--kz-counter-fg: #0a0a0a;
--kz-counter-muted: rgba(10, 10, 10, 0.62);
--kz-counter-size: clamp(44px, 6vw, 72px);
display: grid;
gap: 8px;
color: var(--kz-counter-fg);
}
.kodza-counter__value {
display: flex;
margin: 0;
font-size: var(--kz-counter-size);
font-weight: 600;
font-variant-numeric: tabular-nums;
line-height: 1.1;
letter-spacing: -0.045em;
}
/* Each digit spins in its own window */
.kodza-counter__digit {
display: inline-block;
height: 1.1em;
overflow: hidden;
}
.kodza-counter__digit > span {
display: block;
}
.kodza-counter__digit > span > span {
display: block;
height: 1.1em;
}
.kodza-counter__char {
white-space: pre;
}
.kodza-counter__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
.kodza-counter__label {
margin: 0;
color: var(--kz-counter-muted);
font-size: 15px;
line-height: 1.5;
}
/* Theming example — on a dark background:
.dark-section .kodza-counter {
--kz-counter-fg: #f2f2f0;
--kz-counter-muted: rgba(242, 242, 240, 0.62);
}
*/
/* kodza-guard 894660ff6016 — generated by Kodza, do not edit.
Theme guard: keeps a site's own CSS (WordPress themes, Bootstrap, CSS resets…) off this
component. :not(#_) is always true and weighs as much as an id, so these lines win over
theme rules made of classes and tags. Customise the component through its --kz-* variables. */
/* What the browser gives, on everything the component leaves to it */
.kodza-counter:not(#_),
.kodza-counter__digit:not(#_),
.kodza-counter__char:not(#_),
.kodza-counter__sr:not(#_),
.kodza-counter__digit span:where(:not([class*="kodza-"])):not(#_) {
box-sizing: revert;
}
.kodza-counter__value:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
color: revert;
font-family: revert;
font-style: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-counter__label:not(#_) {
border: revert;
padding: revert;
border-radius: revert;
outline: revert;
text-decoration: revert;
transition: revert;
list-style: revert;
box-sizing: revert;
float: revert;
position: revert;
background-color: revert;
background-image: revert;
box-shadow: revert;
outline-offset: revert;
appearance: revert;
max-width: revert;
max-height: revert;
font-family: revert;
font-weight: revert;
font-style: revert;
letter-spacing: revert;
text-transform: revert;
text-underline-offset: revert;
text-align: revert;
text-indent: revert;
text-shadow: revert;
vertical-align: revert;
}
.kodza-counter__label:not(#_):where(:not([hidden])) {
display: revert;
}
.kodza-counter__label:not(#_):where([hidden]) {
display: none;
}
/* The component's own rules, one step stronger: real buttons and fields, what it sets on tags themes style (links, lists, headings, images…), and the root width (a theme may narrow it, never widen it) */
.kodza-counter__value:not(#_) {
display: flex;
margin: 0;
font-size: var(--kz-counter-size);
font-weight: 600;
line-height: 1.1;
letter-spacing: -0.045em;
}
.kodza-counter__label:not(#_) {
margin: 0;
color: var(--kz-counter-muted);
font-size: 15px;
line-height: 1.5;
}
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Kodza — Counter
// Turns the figure into windows of spinning digits (screen readers keep the plain text), then
// rolls them when the counter comes into view: more turns and a later landing for the digits
// on the right. "kodza:replay" on the element rolls it again.
(() => {
const SELECTOR = '.kodza-counter';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// One instance. Everything it starts is tied to `signal`, so kodza:destroy stops it all
function mount(root, signal) {
const value = root.querySelector('.kodza-counter__value');
if (!value) return;
const text = value.textContent.trim();
const count = (text.match(/\d/g) || []).length;
let rank = 0;
const strips = [];
value.setAttribute('aria-hidden', 'true');
value.after(Object.assign(document.createElement('span'), { className: 'kodza-counter__sr', textContent: text }));
value.replaceChildren(...[...text].map((char) => {
if (!/\d/.test(char)) return Object.assign(document.createElement('span'), { className: 'kodza-counter__char', textContent: char });
// The digits on the right spin more: one turn on the left, up to three on the right
const turns = 1 + Math.round((rank / Math.max(1, count - 1)) * 2);
const column = Object.assign(document.createElement('span'), { className: 'kodza-counter__digit' });
const strip = document.createElement('span');
for (let i = 0; i < (turns + 1) * 10; i++) strip.append(Object.assign(document.createElement('span'), { textContent: i % 10 }));
column.append(strip);
strips.push({ strip, stop: turns * 10 + Number(char), rank: rank++ });
return column;
}));
const land = () => strips.forEach(({ strip, stop }) => (strip.style.transform = `translateY(${-stop * 1.1}em)`));
const roll = () => {
if (reduceMotion) return land();
strips.forEach(({ strip, stop, rank: r }) => {
strip.getAnimations().forEach((animation) => animation.cancel());
strip.style.transform = '';
strip.animate([{ transform: 'translateY(0)' }, { transform: `translateY(${-stop * 1.1}em)` }], {
duration: 1500 + r * 160,
easing: 'cubic-bezier(0.16, 1, 0.3, 1)',
fill: 'forwards',
});
});
};
if (reduceMotion || !('IntersectionObserver' in window)) land();
else {
const io = new IntersectionObserver((entries) => {
if (!entries.some((entry) => entry.isIntersecting)) return;
io.disconnect();
roll();
}, { threshold: 0.6 });
io.observe(root);
signal.addEventListener('abort', () => io.disconnect());
}
root.addEventListener('kodza:replay', roll, { signal });
}
// Kodza lifecycle, the same in every component: `kodza:init` starts the instances inside
// event.detail.root (the whole page by default), `kodza:destroy` stops them and puts their
// markup back. For themes and apps that swap content without a page load.
const instances = new WeakMap();
const find = (scope = document) => [scope, ...scope.querySelectorAll(SELECTOR)].filter((el) => el.matches?.(SELECTOR));
const init = (scope) => find(scope).forEach((root) => {
if (root.classList.contains('is-ready')) return; // already running, maybe from another copy of this script
const controller = new AbortController();
instances.set(root, { controller, html: root.innerHTML, attrs: [...root.attributes].map((a) => [a.name, a.value]) });
mount(root, controller.signal);
root.classList.add('is-ready');
});
const destroy = (scope) => find(scope).forEach((root) => {
const instance = instances.get(root);
if (!instance) return;
instances.delete(root);
instance.controller.abort();
[...root.attributes].forEach((a) => root.removeAttribute(a.name));
instance.attrs.forEach(([name, value]) => root.setAttribute(name, value));
root.innerHTML = instance.html;
});
document.addEventListener('kodza:init', (event) => init(event.detail?.root));
document.addEventListener('kodza:destroy', (event) => destroy(event.detail?.root));
init();
// Loaded in <head>, the script runs before the markup exists: once more when it is parsed
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => init(), { once: true });
})();
'use client';
// Kodza — Counter, for React. From https://kodza.dev/components/counter-animation/
// Kodza License: free to use, client work included. Not to resell or redistribute, ported or not: https://kodza.dev/docs/#print-license
// Next to this file: counter-animation.css and counter-animation.js, the component's CSS and JS from Kodza, as they are.
// Yours to edit: the markup is plain JSX below.
// The script changes this markup once React has rendered it (it adds layers, splits text, moves
// nodes), so React must not patch it afterwards. When a prop changes, the key gives React a fresh
// element: kodza:destroy stops the script on the old one, kodza:init starts it on the new one.
import { useRef, useEffect, type ComponentPropsWithoutRef, type ComponentRef, type CSSProperties } from 'react';
import './counter-animation.css';
export type CounterProps = Omit<ComponentPropsWithoutRef<'div'>, "children" | "vars"> & {
/** Settings, as CSS variables on the root */
vars?: {
/** default: #0a0a0a */
"--kz-counter-fg"?: string | number;
/** default: rgba(10, 10, 10, 0.62) */
"--kz-counter-muted"?: string | number;
/** default: clamp(44px, 6vw, 72px) */
"--kz-counter-size"?: string | number;
};
className?: string;
};
export function Counter({ vars, className, style, ...rest }: CounterProps) {
const ref = useRef<ComponentRef<'div'>>(null);
const classes = ["kodza-counter", className].filter(Boolean).join(' ');
// Everything the markup is made of: when it changes, React gets a fresh element (see the top)
const key = JSON.stringify([classes, vars, style, rest]);
// Starts the script on this element once React has rendered it, stops it when it goes
useEffect(() => {
const root = ref.current;
let live = true;
// @ts-ignore: a plain script, no types to find
import('./counter-animation.js').then(() => {
if (live) document.dispatchEvent(new CustomEvent('kodza:init', { detail: { root } }));
});
return () => {
live = false;
document.dispatchEvent(new CustomEvent('kodza:destroy', { detail: { root } }));
};
}, [key]);
return (
<div key={key} {...rest} className={classes} style={{ ...vars, ...style } as CSSProperties} ref={ref}>
<p className="kodza-counter__value">12,480</p>
<p className="kodza-counter__label">components copied this month</p>
</div>
);
}
Checked
Robots poked at it before you did. Every component goes through the same checks, and again each time it changes.