Animated Donut Chart
A four-slice ring whose boundaries glide on every value change; whatever falls short of 100% stays grey: it shows a whole being filled.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Data has 28 effects, including 1 free. Explore the category →
3 usage examples



How it works
.adn-ring is a disc painted by a conic-gradient of four colours followed by a grey. The four boundaries between colours are variables, --adn-s1 to --adn-s4, registered with @property as <percentage>: the browser therefore knows how to animate them, and a one-second transition makes them glide instead of jumping. A radial mask pierces the centre (--adn-hole).
Each <li class="adn-slice" data-value="…"> in the legend is one slice, four at most. Values are read as percentages of a whole of 100: 35, 25, 20 and 15 cover 95% of the ring, and the remaining 5% keeps the --adn-track colour. If the total exceeds 100, every slice is scaled down by the same ratio.
On appearance (35% of the ring visible, then 150 ms), the four boundaries start at 0 and the ring fills clockwise. After that, a MutationObserver watches the data-value attributes: changing one makes that slice grow or shrink and pushes the following ones.
The script writes each legend row's value as a percentage, in the page language, with one decimal at most ("11.7%"). That text changes at once; only the ring takes its time.
Accessibility
- The legend carries the figures: a
<ul>named byaria-label, each row read as "Rent 35%". The ring isaria-hidden. - The remainder is not stated: the grey part has no row in the legend. If it matters (free room, data left), write it in plain text nearby, such as "5.6 GB left".
- Reduced motion: no glide; the ring is filled on first display and moves from one state to the next without a transition.
- Silent changes: no
aria-liveregion. When a button changes the slices, keep focus on it; the list stays within reach to be read again. - Controls: the effect provides none. The "+" and "−" buttons in the examples are yours to write: real
<button>elements with an accessible name.
Browser compatibility
conic-gradient, @property (for the glide), mask-image and its -webkit- form, aspect-ratio, MutationObserver, IntersectionObserver. In Chromium 149, Firefox 151 and WebKit 26.5: boundaries at 0% off screen, first boundary between 19 and 21% half a second after load, landing on 35, 60, 80 and 95%; a total of 160 scaled down to 100; two rings that do not interfere.
Without @property the ring is correct but switches from one state to the next at once. Without JavaScript it stays entirely grey and the legend has no figures.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0242-root">
<div class="adn-wrap">
<div class="adn-ring" aria-hidden="true"></div>
<ul class="adn-legend" aria-label="Monthly budget">
<li class="adn-slice" data-value="35">Rent</li>
<li class="adn-slice" data-value="25">Groceries</li>
<li class="adn-slice" data-value="20">Energy</li>
<li class="adn-slice" data-value="15">Outings</li>
</ul>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
data-value on each .adn-slice (HTML) |
35, 25, 20, 15 | Slice, as a percentage of the whole. Changing it makes the ring glide to the new state. |
Number of .adn-slice (HTML) |
4 | From one to four. A fifth row would show in the legend with no slice and no figure. |
--adn-c1 to --adn-c4 (CSS) |
#6366f1, #ec4899, #f59e0b, #10b981 | Slice and dot colours, in list order. |
--adn-track (CSS) |
white at 8% | Colour of the remainder, and of the ring before it fills. |
--adn-size (CSS) |
140px | Diameter; never exceeds the container width. |
--adn-hole (CSS) |
40% | Hole radius, as a share of the ring radius: 60% gives a thin ring, 20% an almost full disc. |
--adn-speed (CSS) |
1s | Glide duration, on appearance and on every change. |
--adn-text (CSS) |
white at 70% | Legend text colour. |
--adn-bg, --adn-min-height (CSS) |
#0a0a0f, 300px | Block background and minimum height. |
FAQ
value / total * 100. Otherwise 3, 5 and 2 are read as 3%, 5% and 2%, and the ring stays almost empty. The total to use is that of the whole (the album's 60 stickers), not the sum of the slices, or the ring would always be complete.@property variables and the script are built for four boundaries. Group the smallest into an "Other" slice, or pick Morphing Pie Chart, which takes six.