Skip to content

Sparkline for React

A React sparkline is a tiny trend line for stat tiles and table cells, summarized in words for screen readers. Pass values as a readonly number[], oldest first.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sparkline.json

Revenue

$34.2k▲ 18.6% vs last week

Sparklines in stat tiles

A small trend under a headline number.

Revenue

$12.4K

Sessions

86.4K

Bounce rate

38%

Files to copy

5 folders · 12 files · 3 packages
From theme/src/
  • components/charts/{sparkline.tsx, chart-utils.ts}
  • hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, form.ts, math.ts, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/sparkline.jsonRegistry item: sparkline. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/glass-card/
  • motion/light-follower.ts
  • lib/heading.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json
Packages
pnpm add clsx motion tailwind-merge

Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".

Sparkline props

PropTypeDefaultDescription
values (required)readonly number[]NoneValues, oldest first. Non-numeric entries are skipped.
variant"accent" | "muted""accent""muted" de-emphasises the trend; "accent" draws it in the first chart colour.
tone"accent" | "muted"undefinedOld name of variant (it is a visual form, not a semantic colour). Still honoured; variant wins.
heightnumber40Height of the chart in px; the width follows the container.
areabooleantrueSoft fill under the line (a gradient that fades to transparent).
curveChartCurve"monotone""monotone" (default): a smooth curve that never overshoots. "linear": straight segments.
glowbooleantrueSoft glow on the latest point in dark mode.
emptyStateReactNode"No data"Shown when there are no values.
localestringthe browser'sLocale for the numbers in the spoken summary (e.g. "de").
labelsPartial<SparklineLabels>defaultSparklineLabelsEvery other string, for translation: labels={{ summary: "…" }}; omitted keys keep the English of defaultSparklineLabels. Its only key is listed in the key table under the props table.
aria-labelstringNoneNames the trend (e.g. "Weekly signups"); a summary of the values (count, min, max, latest) is appended. Without it the sparkline is decorative.
classNamestringNoneAdds extra classes to the outer element.
SparklineLabels keys and English defaults (1)
Pass any key in labels; the rest keep the defaults of defaultSparklineLabels.
KeyEnglish default
summary({ count, min, max, latest, format }) => `${count} ${count === 1 ? "point" : "points"}, min ${format(min)},...

When to use a sparkline

Use a React sparkline when there is no room for a full chart but the direction of a number matters: KPI tiles, table rows, list items. It answers one question, is this going up or down, at a glance.

Keep sparklines honest: use the same time range for every tile in a row, label the period near the number ("last 7 days"), and do not mix a rising line with a bad number without saying so in the label. Because the line has no axis, a sparkline can exaggerate small changes; the arrow and percent change next to the headline number give the scale.

Skip it when readers need exact values or a time axis: a sparkline has none and exaggerates small changes, so use a React line chart. Skip it for a single data point, and for series with fewer than about five points, where the number alone is clearer. For counts per bucket use the sparkbar, and for whole dashboards of tiles see the web analytics dashboard.

Frequently asked questions

All exports on this page

  • Sparkline — A tiny trend line for stat tiles.
  • defaultSparklineLabels — The built-in English strings of Sparkline; spread it into your own labels and change what you need.

Keyboard

KeysAction
TabA sparkline is a static image: it takes no focus and has no keys. Read the number beside it, or open the full line chart.

Accessibility

  • The sparkline is an image with a name: write the direction into the aria-label ("Revenue trend, rising").
  • It never carries information a sighted reader could not also get from the number beside it.
  • Reduced motion: the line is drawn at once, without the draw-in.

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .