Percent
import { useEffect, useRef, useState } from 'react';
const css = `
.loader-percent { position: relative; display: grid; place-items: center; width: 96px; height: 96px; }
.loader-percent__ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.loader-percent__track { fill: none; stroke: light-dark(#ebedf0, #232529); stroke-width: 4; }
.loader-percent__bar {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 4;
stroke-linecap: round;
stroke-dasharray: 1;
}
.loader-percent__value {
position: relative;
color: light-dark(#373a40, #f1f2f3);
font-size: 20px;
font-weight: 600;
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
}
.loader-percent__value small { font-size: 11px; color: light-dark(#5f626a, #a7abb2); margin-left: 1px; }
.loader-percent__done {
position: absolute;
width: 26px;
height: 26px;
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 2.5;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
transition: stroke-dashoffset 0.35s ease, opacity 0.2s ease;
}
`;
// Progress (0–1) against time (s): the way real loads feel. Quick start, a long slow
// middle, a stall near the end, then the last stretch at once.
const KEYS: [number, number][] = [
[0, 0],
[0.5, 0.34],
[1.6, 0.62],
[2.2, 0.71],
[3.1, 0.74],
[3.5, 1],
];
const DONE = 3.5;
const HOLD = 1.1;
function at(t: number) {
for (let i = 1; i < KEYS.length; i++) {
const [t1, v1] = KEYS[i];
const [t0, v0] = KEYS[i - 1];
if (t <= t1) {
const u = (t - t0) / (t1 - t0);
return v0 + (v1 - v0) * (1 - (1 - u) ** 2);
}
}
return 1;
}
export function PercentLoader() {
const bar = useRef<SVGCircleElement>(null);
const [pct, setPct] = useState(0);
useEffect(() => {
const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
let start = performance.now();
let raf = 0;
const tick = (now: number) => {
let t = (now - start) / 1000;
if (t > DONE + HOLD) {
start = now;
t = 0;
}
const p = at(t);
bar.current!.style.strokeDashoffset = String(1 - p);
setPct(Math.round(p * 100));
raf = requestAnimationFrame(tick);
};
if (still) {
bar.current!.style.strokeDashoffset = '0.4';
setPct(60);
} else raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, []);
const done = pct >= 100;
return (
<>
<style>
{css}
</style>
<div className="loader-percent" role="progressbar" aria-label="Loading" aria-valuemin={0} aria-valuemax={100} aria-valuenow={pct}>
<svg className="loader-percent__ring" viewBox="0 0 96 96" aria-hidden="true">
<circle className="loader-percent__track" cx={48} cy={48} r={40} />
<circle ref={bar} className="loader-percent__bar" cx={48} cy={48} r={40} pathLength={1} strokeDashoffset={1} />
</svg>
<span className="loader-percent__value" aria-hidden="true" style={{ opacity: done ? 0 : 1 }}>
{pct}
<small>%</small>
</span>
<svg
className="loader-percent__done"
viewBox="0 0 24 24"
aria-hidden="true"
style={{ strokeDashoffset: done ? 0 : 1, opacity: done ? 1 : 0 }}
>
<path d="M5 12.5l4.5 4.5L19 7.5" pathLength={1} />
</svg>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initLoaderPercent(el) on the mounted element instead.
<div class="loader-percent" role="progressbar" aria-label="Loading" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
<svg class="loader-percent__ring" viewBox="0 0 96 96" aria-hidden="true">
<circle class="loader-percent__track" cx="48" cy="48" r="40"></circle>
<circle class="loader-percent__bar" cx="48" cy="48" r="40" pathLength="1" stroke-dashoffset="1"></circle>
</svg>
<span class="loader-percent__value" aria-hidden="true" style="opacity:1">0<small>%</small></span>
<svg class="loader-percent__done" viewBox="0 0 24 24" aria-hidden="true" style="stroke-dashoffset:1;opacity:0">
<path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"></path>
</svg>
</div>.loader-percent { position: relative; display: grid; place-items: center; width: 96px; height: 96px; }
.loader-percent__ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.loader-percent__track { fill: none; stroke: light-dark(#ebedf0, #232529); stroke-width: 4; }
.loader-percent__bar {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 4;
stroke-linecap: round;
stroke-dasharray: 1;
}
.loader-percent__value {
position: relative;
color: light-dark(#373a40, #f1f2f3);
font-size: 20px;
font-weight: 600;
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
}
.loader-percent__value small { font-size: 11px; color: light-dark(#5f626a, #a7abb2); margin-left: 1px; }
.loader-percent__done {
position: absolute;
width: 26px;
height: 26px;
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 2.5;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
transition: stroke-dashoffset 0.35s ease, opacity 0.2s ease;
}function initLoaderPercent(root) {
var bar = root.querySelector('.loader-percent__bar');
var value = root.querySelector('.loader-percent__value');
var done = root.querySelector('.loader-percent__done');
if (!bar || !value || !done) return;
// Progress (0-1) against time (s): a quick start, a long slow middle, a stall near the end, then the rest at once.
var KEYS = [[0, 0], [0.5, 0.34], [1.6, 0.62], [2.2, 0.71], [3.1, 0.74], [3.5, 1]];
var DONE = 3.5;
var HOLD = 1.1;
function at(t) {
for (var i = 1; i < KEYS.length; i++) {
if (t <= KEYS[i][0]) {
var u = (t - KEYS[i - 1][0]) / (KEYS[i][0] - KEYS[i - 1][0]);
return KEYS[i - 1][1] + (KEYS[i][1] - KEYS[i - 1][1]) * (1 - (1 - u) * (1 - u));
}
}
return 1;
}
function show(p) {
var pct = Math.round(p * 100);
var finished = pct >= 100;
bar.style.strokeDashoffset = String(1 - p);
value.firstChild.textContent = String(pct);
value.style.opacity = finished ? '0' : '1';
done.style.strokeDashoffset = finished ? '0' : '1';
done.style.opacity = finished ? '1' : '0';
root.setAttribute('aria-valuenow', String(pct));
}
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
show(0.6);
return;
}
var start = performance.now();
var raf = 0;
function tick(now) {
var t = (now - start) / 1000;
if (t > DONE + HOLD) {
start = now;
t = 0;
}
show(at(t));
raf = requestAnimationFrame(tick);
}
raf = requestAnimationFrame(tick);
return function () { cancelAnimationFrame(raf); };
}
document.querySelectorAll('.loader-percent').forEach(initLoaderPercent);Goal: Create a "Percent" loader.
Visual behavior: A progress ring with a percentage that loads the way real progress feels: a quick start, a long slow middle, a stall near the end, then the last stretch at once, a tick, and round again.
Technique:
- The ring is an SVG circle with pathLength 1, rotated -90deg so it starts at the top; its dashoffset is 1 minus progress.
- Progress against time is a short list of keyframes (0, 34%, 62%, 71%, 74%, 100%) with ease-out between them, which gives the start, slog, stall and finish.
- At 100% the number fades out and a tick draws in; after a 1.1s hold the cycle restarts.
- The root is a progressbar with aria-valuenow kept current.
Accessibility: The root has role="progressbar", aria-label="Loading" and a live aria-valuenow. Under prefers-reduced-motion it shows a still 60%.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Percent" loader.
Visual behavior: A progress ring with a percentage that loads the way real progress feels: a quick start, a long slow middle, a stall near the end, then the last stretch at once, a tick, and round again.
Technique:
- The ring is an SVG circle with pathLength 1, rotated -90deg so it starts at the top; its dashoffset is 1 minus progress.
- Progress against time is a short list of keyframes (0, 34%, 62%, 71%, 74%, 100%) with ease-out between them, which gives the start, slog, stall and finish.
- At 100% the number fades out and a tick draws in; after a 1.1s hold the cycle restarts.
- The root is a progressbar with aria-valuenow kept current.
Accessibility: The root has role="progressbar", aria-label="Loading" and a live aria-valuenow. Under prefers-reduced-motion it shows a still 60%.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
A progress ring with a percentage that loads the way real progress feels: a quick start, a long slow middle, a stall near the end, then the last stretch at once, a tick, and round again.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- continuous, loop, draw, state change
- Techniques
- raf, stroke dashoffset, svg stroke
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
The root has role="progressbar", aria-label="Loading" and a live aria-valuenow. Under prefers-reduced-motion it shows a still 60%.