Sparkline React chart component for Tailwind CSS v4
v1.0.0Added in 1.0.0
A React sparkline: a word-sized chart for table cells, list rows, KPI tiles and running text, as a line, an area, bars or win / loss ticks.
Read-only by default: the line draws in from the left the first time it scrolls into view and the last point pops in as a dot; screen readers hear the label and a summary ("from $8,200 to $12,480, +52.2%"). With interactive on, the sparkline becomes one tab stop: hover it with a mouse, or tap and drag sideways with a finger (vertical drags still scroll the page), and a compact readout above it shows the point's label and value while a hairline and a dot follow. The whole row height (8px above and below) is the touch target, a second tap on the same point or a tap outside clears it. From the keyboard, Tab focuses it, Left / Right walk the points, Home / End jump to the ends, Page Up / Page Down move by 10, Escape clears, and a polite live region reads each point. When the data changes the line and bars glide to their new shape. Reduced motion shows everything at once.
Sparkline is a Pro React chart component in the React chart and stat components category, written in TypeScript for React 19 and Tailwind CSS v4. It installs as source with npx wingo-ui@latest add sparkline, together with Chart kit, Trend badge, useControllableState, useLocale, Motion presets and 3 more and the npm packages motion, d3-shape and d3-scale.
Add to a project
Requirements: React 19 and Tailwind CSS v4, in Next.js (App Router or Pages), Vite or React Router. Installation guide · Next.js setup · Vite setup
npx wingo-ui@latest add sparklineSparkline is part of Pro, with 298 more Pro items: $8 a month or $150 once. 14-day refund before you download any Pro item. See plans
Usage
Import Sparkline from @/components/ui/sparkline.
import { Sparkline, SparklineWithValue } from "@/components/ui/sparkline"
const revenue = [8200, 8650, 8400, 9100, 9480, 9230, 10150, 10600, 10380, 11420, 11900, 12480]
export function ClientRow() {
return (
<div className="flex items-center justify-between gap-3">
<span className="text-sm font-medium">Tech Solutions Inc.</span>
<Sparkline
data={revenue}
valueFormat="currency"
locale="en-US"
label="Revenue, last 12 weeks"
interactive
/>
<SparklineWithValue
data={revenue}
type="area"
valueFormat="currency"
locale="en-US"
layout="responsive"
min={0}
max={16000}
/>
</div>
)
}Props
data*(number | null)[] | { value: number | null; label?: string; date?: string }[]The values, oldest first. Rows can carry a label ("Week 39") or an iso date for the readout; null leaves a gap in the line.
typedefault"line""line" | "area" | "bar" | "win-loss"line, line over a soft fading fill, bars from zero, or win-loss: equal ticks up for positive and down for negative values (streaks, daily goals). Bars fall back to a line above 120 points.
widthdefault96numberWidth in px. 0 fills the container (the parent needs a width, e.g. a grid cell or a flex-1 box).
heightdefault28numberHeight in px. 28 reads well in a phone row; 16 sits inside a line of text.
tonedefault"neutral""neutral" | "brand" | "success" | "warning" | "danger" | "info"The stroke and fill color. neutral is the ink (black in light mode, white in dark mode).
colordefault""stringAny CSS color, a palette slot ("series-3") or a tone name. Replaces tone and trendColor.
trendColordefaultfalsebooleanColor by the direction from the first to the last value: success when it rose, danger when it fell, the ink when flat. Win-loss paints wins green and losses red.
invertTrenddefaultfalsebooleanDown is good (costs, churn, response time): a fall turns green under trendColor and reads as positive (data-intent).
curvedefault"monotone""monotone" | "linear" | "natural" | "step"How the line joins the points. monotone never overshoots a value; step suits counts that jump.
strokeWidthdefault1.5numberLine width in px, with round caps and joins.
showLastdefaulttruebooleanA 5px dot on the last point, ringed in the surface color. For bars, the last bar keeps the full color and the others soften.
showMinMaxdefaultfalsebooleanSmall hollow dots at the lowest and the highest point (bars: those bars in full color).
referencedefault"none""none" | "first" | "average" | "zero"A dashed hairline at the first value, the average or zero (zero widens the range to include it).
surfacedefault""stringThe color behind the sparkline, used for the rings around dots. Empty is the surface token.
minnumberLower bound of the value range; the data's minimum when unset. Share min and max across the rows of a table so the sparklines compare.
maxnumberUpper bound of the value range; the data's maximum when unset. The Clients table example shares one range across rows.
interactivedefaultfalsebooleanFocusable and inspectable: hover, tap, drag or arrow keys show each point in a compact readout pinned above the sparkline.
activeIndexnumber | nullThe inspected point, controlled (with onActiveIndexChange), so a value next to the sparkline can follow the scrub.
defaultActiveIndexdefault"null"number | nullThe inspected point on mount, uncontrolled; null starts with no readout. Needs interactive.
onActiveIndexChange(index: number | null) => voidCalled when a point is inspected or the readout clears.
valueFormatdefault"number"ChartValueFormat = "number" | "compact" | "currency" | "percent"How values print in the readout and the accessible summary ("$12,480" with currency and en-US).
currencydefault"USD"stringISO 4217 code for valueFormat="currency", printed with its narrow symbol.
formatValue(value: number, context: "tooltip" | "label" | "value") => stringFull control over printed values, e.g. v => `${v} orders`.
localedefault""stringIntl locale for values and dates. Empty follows the UIProvider, then the page.
labeldefault""stringThe accessible name, e.g. "Revenue, last 12 weeks". A summary of the first and last value and the change is appended.
animateddefaulttruebooleanDraws in the first time it scrolls into view (0.6s), the last dot pops in after it; data changes glide either way. Off under reduced motion.
labels{ summary?: (first: string, last: string, change: string) => string; empty?: string; point?: (index: number, count: number) => string; inspectHint?: string }Screen reader strings. Defaults "from {first} to {last}, {change}", "No data", "{n} of {count}" and the arrow-key hint. Pass only the keys you translate.
classNamesPartial<Record<"svg" | "line" | "area" | "bar" | "last" | "reference" | "tooltip", string>>Extra classes for the inner parts.
classNamestringExtra classes for the root, e.g. "align-[-0.2em]" inside text. Other props (id, data-*, aria-*, events) spread onto the root span.
Parts
DEFAULT_SPARKLINE_LABELS
constantThe English screen reader strings: the summary "from {first} to {last}, {change}", "No data", "{n} of {count}" and the arrow-key hint.
SparklineWithValue
componentA sparkline with the current value and a TrendBadge, for table cells and list rows. value = the last point (the inspected point while scrubbing); delta = the % change first -> last (with deltaFormat "number" / "currency": last - first); deltaFormat = "percent"; badgeVariant = "ghost"; badgeSize = "sm"; showDelta = true; layout "inline" (default) | "stacked" (value and badge over the sparkline) | "responsive" (stacked below 640px); badgeLabels for the badge's spoken text; classNames { sparkline, value, badge, meta, ...the Sparkline slots }. className and style go to the wrapper, every other prop to the Sparkline, and activeIndex / onActiveIndexChange work the same. Props: SparklineWithValueProps.
Examples
Clients table
SparklineWithValue with shared min / max so rows compare; stacked under the value on phones.
Types
line, area, bar and win-loss, filling their tiles (width 0).
Trend colors
trendColor paints by direction; invertTrend makes falling costs green and rising returns red.
Inside text
64 x 16 sparklines on the text baseline (align-[-0.2em]).
Scrub to read
interactive, reference="average" and min / max dots; the big number follows activeIndex.
KPI card footer
type="area" at 48px filling the card, inspectable.
Live data
Data updates glide on a smooth spring instead of redrawing.
Edge cases
One value, all equal, gaps, no data, negatives and 365 points.
Dependencies
Files
- components/ui/sparkline.tsx
FAQ
Is the React Sparkline chart component free?
The preview, props and docs are free; copying the source needs a Pro plan. See plans.
How do I install Sparkline?
Run npx wingo-ui@latest add sparkline. It also adds the Wingo UI items it builds on (Chart kit, Trend badge, useControllableState, useLocale, Motion presets and 3 more) and the npm packages motion, d3-shape and d3-scale. With shadcn, add the @wingo-ui registry with your API key, then run npx shadcn@latest add @wingo-ui/sparkline.
See also
Used in
More React chart and stat components
Articles using this component
- Shadcn KPI Cards: Deltas, Sparklines and Goal Bars
Component guides9 min read
- React Sparkline: Table Cells, KPI Tiles, Delta Chips
Component guides9 min read