Tearsheet

Issue 01 · Data · p.40

Donut chart

A CSS conic-gradient donut with a total in the middle and a legend that carries the real numbers.

Why it works: Keep donuts to five slices or fewer. The legend repeats every value as text and uses patterns of position and order, not colour alone.

Try it:
Receipt: axe clean · contrast 17.41:1 · 0 tab stops · RTL ✓ · long text ✓

Tab order: nothing here takes focus (it is content, not controls).

What assistive tech is given

- figure "Photos 24 GB Video 14 GB Documents 6 GB Other 4 GB":
  - 'img "Storage used: 48 of 100 gigabytes. Photos 24, Video 14, Documents 6, Other 4."': 48 of 100 GB
  - list:
    - listitem: Photos 24 GB
    - listitem: Video 14 GB
    - listitem: Documents 6 GB
    - listitem: Other 4 GB

Automated checks in CI (axe in Chromium, reduced motion on). They catch a lot, not everything: still try it with a screen reader.

See it in the zine npx -y tearsheet add donut-chart

Needs the shared tokens.css once per project.

HTML + CSS

index.html
<!-- tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html -->
<figure class="donut">
  <div class="donut-ring" role="img" aria-label="Storage used: 48 of 100 gigabytes. Photos 24, Video 14, Documents 6, Other 4.">
    <span class="donut-total"><b>48</b> of 100 GB</span>
  </div>
  <figcaption>
    <ul class="donut-legend">
      <li><i style="--c: var(--ui-accent)"></i>Photos <b>24 GB</b></li>
      <li><i style="--c: #0d9488"></i>Video <b>14 GB</b></li>
      <li><i style="--c: #c2410c"></i>Documents <b>6 GB</b></li>
      <li><i style="--c: #a855f7"></i>Other <b>4 GB</b></li>
    </ul>
  </figcaption>
</figure>
styles.css
/* tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html */
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; margin: 0; }
.donut-ring {
  position: relative; display: grid; place-items: center; width: 170px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--ui-accent) 0 24%, #0d9488 0 38%, #c2410c 0 44%, #a855f7 0 48%, var(--ui-surface-2) 0);
}
.donut-ring::before { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--ui-bg); }
.donut-total { position: relative; display: grid; text-align: center; font-size: 13px; color: var(--ui-muted); }
.donut-total b { font-size: 34px; line-height: 1; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.donut-legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.donut-legend li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px; min-width: 180px; }
.donut-legend i { width: 14px; height: 14px; border-radius: 4px; background: var(--c); }
.donut-legend b { font-variant-numeric: tabular-nums; }

React

DonutChart.jsx
/* tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html */
import './DonutChart.css';

export function DonutChart() {
  return (
    <figure className="donut">
      <div className="donut-ring" role="img" aria-label="Storage used: 48 of 100 gigabytes. Photos 24, Video 14, Documents 6, Other 4.">
        <span className="donut-total"><b>48</b> of 100 GB</span>
      </div>
      <figcaption>
        <ul className="donut-legend">
          <li><i style={{ '--c': 'var(--ui-accent)' }}></i>Photos <b>24 GB</b></li>
          <li><i style={{ '--c': '#0d9488' }}></i>Video <b>14 GB</b></li>
          <li><i style={{ '--c': '#c2410c' }}></i>Documents <b>6 GB</b></li>
          <li><i style={{ '--c': '#a855f7' }}></i>Other <b>4 GB</b></li>
        </ul>
      </figcaption>
    </figure>
  );
}
DonutChart.css
/* tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html */
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; margin: 0; }
.donut-ring {
  position: relative; display: grid; place-items: center; width: 170px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--ui-accent) 0 24%, #0d9488 0 38%, #c2410c 0 44%, #a855f7 0 48%, var(--ui-surface-2) 0);
}
.donut-ring::before { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--ui-bg); }
.donut-total { position: relative; display: grid; text-align: center; font-size: 13px; color: var(--ui-muted); }
.donut-total b { font-size: 34px; line-height: 1; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.donut-legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.donut-legend li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px; min-width: 180px; }
.donut-legend i { width: 14px; height: 14px; border-radius: 4px; background: var(--c); }
.donut-legend b { font-variant-numeric: tabular-nums; }

Vue

DonutChart.vue
<!-- tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html -->
<template>
  <figure class="donut">
    <div class="donut-ring" role="img" aria-label="Storage used: 48 of 100 gigabytes. Photos 24, Video 14, Documents 6, Other 4.">
      <span class="donut-total"><b>48</b> of 100 GB</span>
    </div>
    <figcaption>
      <ul class="donut-legend">
        <li><i style="--c: var(--ui-accent)"></i>Photos <b>24 GB</b></li>
        <li><i style="--c: #0d9488"></i>Video <b>14 GB</b></li>
        <li><i style="--c: #c2410c"></i>Documents <b>6 GB</b></li>
        <li><i style="--c: #a855f7"></i>Other <b>4 GB</b></li>
      </ul>
    </figcaption>
  </figure>
</template>

<style scoped>
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; margin: 0; }
.donut-ring {
  position: relative; display: grid; place-items: center; width: 170px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--ui-accent) 0 24%, #0d9488 0 38%, #c2410c 0 44%, #a855f7 0 48%, var(--ui-surface-2) 0);
}
.donut-ring::before { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--ui-bg); }
.donut-total { position: relative; display: grid; text-align: center; font-size: 13px; color: var(--ui-muted); }
.donut-total b { font-size: 34px; line-height: 1; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.donut-legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.donut-legend li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px; min-width: 180px; }
.donut-legend i { width: 14px; height: 14px; border-radius: 4px; background: var(--c); }
.donut-legend b { font-variant-numeric: tabular-nums; }
</style>

Svelte

DonutChart.svelte
<!-- tearsheet donut-chart v7cb7f462 · https://qusaialjbali.github.io/tearsheet/zine/parts/donut-chart.html -->
<figure class="donut">
  <div class="donut-ring" role="img" aria-label="Storage used: 48 of 100 gigabytes. Photos 24, Video 14, Documents 6, Other 4.">
    <span class="donut-total"><b>48</b> of 100 GB</span>
  </div>
  <figcaption>
    <ul class="donut-legend">
      <li><i style="--c: var(--ui-accent)"></i>Photos <b>24 GB</b></li>
      <li><i style="--c: #0d9488"></i>Video <b>14 GB</b></li>
      <li><i style="--c: #c2410c"></i>Documents <b>6 GB</b></li>
      <li><i style="--c: #a855f7"></i>Other <b>4 GB</b></li>
    </ul>
  </figcaption>
</figure>

<style>
.donut { display: flex; flex-wrap: wrap; align-items: center; gap: 28px; margin: 0; }
.donut-ring {
  position: relative; display: grid; place-items: center; width: 170px; aspect-ratio: 1; border-radius: 50%;
  background: conic-gradient(var(--ui-accent) 0 24%, #0d9488 0 38%, #c2410c 0 44%, #a855f7 0 48%, var(--ui-surface-2) 0);
}
.donut-ring::before { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--ui-bg); }
.donut-total { position: relative; display: grid; text-align: center; font-size: 13px; color: var(--ui-muted); }
.donut-total b { font-size: 34px; line-height: 1; color: var(--ui-text); font-variant-numeric: tabular-nums; }
.donut-legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; font-size: 14px; }
.donut-legend li { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 10px; min-width: 180px; }
.donut-legend i { width: 14px; height: 14px; border-radius: 4px; background: var(--c); }
.donut-legend b { font-variant-numeric: tabular-nums; }
</style>