How it works
An inline SVG drawn at its exact pixel size, so the dot stays round and the stroke stays crisp. The curve is a monotone cubic: it passes through every point and never bulges past a peak or a dip, which a plain smoothing would. The line draws in with stroke-dashoffset on a normalised path length, the area fades in after it, and the last-value dot appears with a halo that swells once and settles. Pointing anywhere over it moves the dot to the nearest point on a spring and reports it through onActiveChange, so a table cell can show that day's value next to it.
Use it for
- Trends beside a number in a table, a list or a KPI card, where shape matters more than exact values.
Look elsewhere when
- When people need axes, units or comparisons between series: use a line chart.
Usage
import { Sparkline } from './Sparkline.jsx'
export function VisitorsCell({ history }) {
return (
<Sparkline
data={history}
width={96}
height={28}
variant="area"
tone={1}
label={`Visitors from ${history[0]} to ${history.at(-1)} over 14 days`}
formatValue={(n) => n.toLocaleString('en-US')}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
data | number[] | { value: number }[] | — | Values in time order. Non-numbers are skipped. |
width / height | number | 96 / 28 | Size in px; the chart draws at exactly this size so dots stay round. |
variant | 'line' | 'area' | 'line' | A line alone, or with a gradient fill that fades out at the bottom. |
tone / color | 1-8 / string | 1 | --ds-chart-N, or any colour. |
smooth | boolean | true | A monotone curve that passes through every point without overshooting; false draws straight segments. |
dot / baseline | boolean / number | true / - | The last-value dot, and an optional dashed reference line at a value. |
tooltip / formatValue / onActiveChange | boolean / (v) => string / (index, value) => void | true | A value tag while pointing; or turn it off and show the value yourself with onActiveChange. |
label | string | — | Accessible name. By default it states the first, last, lowest and highest values. |
Accessibility
- The chart is one image with a text summary (first, last, low and high by default); pass label for a sentence in your own words.
- The SVG itself is hidden from assistive technology; the value tag is decorative.
- Keep the number next to it in text, as the demo does: the chart is a supplement, not the only carrier of the value.
- Reduced motion removes the draw, the halo pulse and the dot slide.
Motion
Line: 900ms draw on the reveal curve. Area: 700ms fade from 300ms. Dot: appears at 760ms; halo swells and settles over 1200ms. Pointing: 260ms spring slide.
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.
Sparkline.jsxsparkline.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

