Donut Chart CSS
A donut chart with no SVG: one conic gradient computed from the legend, pierced by a mask, that enters with a quarter turn while fading in.
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
The ring is an empty <div class="dnx-donut">. Its background is a conic-gradient: a series of coloured sectors whose boundaries the script writes into the --dnx-stops variable. A radial mask makes the centre transparent, except for a band --dnx-thickness wide: through the hole, you see whatever is behind.
The data is the legend: each <li data-value="…"> is one slice. The script adds the values up and computes each share (items, hectares, minutes: any unit works), then adds a colour dot and the percentage to every row, written in the page language with one decimal at most.
Until it is 35% visible, the ring is transparent. The root then receives the dnx-on class: the ring makes a clockwise quarter turn while appearing, in 1 s, once only. Slices are not drawn one by one; the whole block arrives.
After that the chart is frozen. Changing a data-value once the ring is displayed redraws nothing: for other data, plan another block (one per tab, for example).
Accessibility
- The legend is the content: a real
<ul>named byaria-label, each row reading "Writing 40%". The ring getsaria-hidden: it says nothing more. - Hidden legend: with
data-legend="hidden"on the root, the list disappears from view but is still read by screen readers. Handy for a mini ring; give the figures as text next to it for everyone else. - Reduced motion: no rotation, no fade, the ring is there from the start.
- Colours: six original hues, designed for a dark background; the written percentage saves telling two neighbours apart. From the 7th slice on, colours start over.
- No interaction: nothing to hover or click, so nothing to reach with the keyboard.
Browser compatibility
conic-gradient, mask and its -webkit-mask form, aspect-ratio (it gives the ring its height), IntersectionObserver. In Chromium 149, Firefox 151 and WebKit 26.5: ring transparent off screen, mid-rotation 0.4 s after it arrives (opacity between 0.65 and 0.69), legend "40%, 25%, 20%, 15%" and the same cut-out hole in all three.
Without JavaScript the ring stays invisible (its starting opacity is 0) and the legend shows its labels without percentages: write the figures in the text if the page must read without scripts. Without aspect-ratio, the ring has no height and cannot be seen.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0236-root">
<div class="dnx-donut"></div>
<ul class="dnx-legend" aria-label="Time spent per task">
<li data-value="40">Writing</li>
<li data-value="25">Proofreading</li>
<li data-value="20">Layout</li>
<li data-value="15">Sending</li>
</ul>
</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 <li> (HTML) |
40, 25, 20, 15 | Slice value, in whatever unit you like. Read on display, not afterwards. |
Number of <li> (HTML) |
4 | One slice per row, no limit; six colours, which repeat from the 7th. |
data-legend="hidden" on the root (HTML) |
absent | Takes the legend off the screen while leaving it to screen readers. |
--dnx-c1 to --dnx-c6 (CSS) |
#6366f1, #d946ef, #06b6d4, #10b981, #f59e0b, #ec4899 | Slice and dot colours, in list order. |
--dnx-size (CSS) |
150px | Diameter; the ring never exceeds the width of its container. |
--dnx-thickness (CSS) |
30px | Width of the band; the rest of the disc is the hole. |
--dnx-text, --dnx-muted (CSS) |
white at 80% and at 50% | Colour of the legend labels and percentages. |
--dnx-bg, --dnx-min-height (CSS) |
#0a0a0f, 300px | Block background and minimum height; transparent and 0 to drop it into a card. |
lang on the page or a parent (HTML) |
browser language | How percentages are written: "40.4%" or "40,4 %". |
FAQ
.dnx-donut in a position: relative block and add your content there with position: absolute; inset: 0, centred. Do not put it inside .dnx-donut: the mask would cut it out and it would turn with the ring.data-value attributes on load, then one last time when the ring becomes visible. For states known in advance, place one block per state and show only one. For slices that glide from one value to another, see Animated Donut Chart.