How it works
A 12px pill with absolutely placed segments separated by 1px borders in the surface colour, so the gaps stay crisp on any background. The whole bar is revealed with one clip-path sweep from the left on the reveal curve, so it reads as a single stroke rather than separate pieces; the marker then drops onto it on a spring. The marker is a dark chip above a 2px pin that crosses the bar with a ring in the surface colour; near either end it aligns inward. Pointing at a segment or its legend row fades the others to 30%.
Use it for
- Composition of one whole: storage, a budget, time spent, a portfolio.
- A value placed on a banded scale: a score, a quality index, a risk level.
Look elsewhere when
- Comparing many wholes side by side: use a stacked bar chart.
- More than about seven categories: group the small ones.
Usage
import { CategoryBar } from './CategoryBar.jsx'
export function StorageUse({ usage }) {
return (
<CategoryBar
label="Storage use"
total={100}
data={[
{ name: 'Photos', value: usage.photos },
{ name: 'Documents', value: usage.documents, tone: 3 },
{ name: 'Free', value: 100 - usage.used, tone: 'track' },
]}
marker={{ value: 80, label: 'Alert at 80 GB' }}
formatValue={(v) => `${v} GB`}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
data | { name: string, value: number, tone?: 1-8 | 'track', color?: string, display?: string }[] | — | Segments left to right. tone 'track' draws an empty part (free space); display replaces the value in the legend, for example a range. |
total | number | — | The whole; defaults to the sum. Anything left over stays empty. |
marker | { value: number, label?: string } | — | A dark chip and a pin at a value, aligned so it stays inside near either end. |
boundaries / legend | boolean | false / true | Cumulative values under the segment edges (crowded ones are skipped), and a legend with value and share. |
formatValue / formatShare | (v) => string / (pct) => string | — | Number formats; return '' from formatShare to hide shares. |
label | string | 'Breakdown' | Start of the accessible name; every category, its value and share and the marker are appended. |
Accessibility
- The bar is one image whose accessible name lists every category with its value and share, and the marker label.
- The legend repeats it visually and is hidden from screen readers to avoid reading it twice.
- Hover highlighting is a visual aid only; nothing is lost without a pointer.
- Reduced motion shows the bar and marker at once.
Motion
Bar: one 1000ms clip-path sweep on the reveal curve. Marker: drops from 520ms with a 520ms spring. Highlight: 160ms.
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.
CategoryBar.jsxcategory-bar.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

