Sparkline
An ultra-compact inline trendline with magnetic scrubber and auto-trend color for table cells and stat cards.
Used forData table rowsStat & metric cardsFinancial watchlistsServer & CPU monitors
Install with the shadcn CLI
Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/sparkline.json. More
Templates
Need the whole page?
65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.
Where it’s used
Data table rows
Show 30-day activity, revenue, or usage trends directly inside table cells.
Stat & metric cards
Sit beside a prominent KPI number to provide immediate historical context.
Financial watchlists
Compact stock, crypto, or commodity price tickers with green/red directional indicators.
Server & CPU monitors
Display live CPU load, memory usage, or ping latency across a grid of instances.
What it handles for you
Dropping a chart into a table cell usually causes layout jitter, blurry SVG scaling, and missing hover tooltips. Sparkline handles continuous width measurement, smooth cubic curve calculation, and magnetic hover snapping out of the box.
Zero layout shift
Renders cleanly within table cells and flex rows without shifting surrounding cell boundaries or altering line heights.
Smooth cubic curves
Generates tangent-continuous cubic bezier curves rather than harsh jagged polylines.
Magnetic scrubber
Tracks mouse or touch coordinates and snaps to the nearest discrete data point with a guide line and snapped dot.
Floating micro-tooltip
Shows the exact value and optional date timestamp directly above the active point, constrained within viewport bounds.
Dynamic auto-trend
Automatically detects whether the final point is higher than the initial point, applying emerald or rose tokens accordingly.
Multiple visual styles
Switches seamlessly between smooth line, area gradient fill, and discrete vertical bars.
Overview
Full chart libraries take up 200px of height, require large bundles, and break layout when dropped into table rows or compact metric strips. Sparkline is an ultra-lightweight hairline trendline that fits in a single line. It computes smooth cubic bezier curves across any container width with zero layout shift, renders an optional delicate gradient wash, and provides an interactive magnetic scrubber that snaps to data points with micro-tooltip readouts on hover. Dynamic auto-trend colors emerald for gains or rose for dips automatically.
States
- rest
- Clean hairline SVG curve with an optional subtle gradient fill. A subtle dot anchors the latest data point.
- hover / scrub
- Pointer movement snaps to the nearest data point, rendering a dashed vertical guide and a micro-tooltip with exact values.
- positive trend
- When the last point is greater than or equal to the first, applies theme emerald tokens.
- negative trend
- When the last point dips below the first, applies theme rose tokens.
- bars
- Renders discrete rounded vertical bars with proportional opacity highlighting hovered columns.
Usage
Table row with 14-day revenue trend
Embed Sparkline directly inside table cells alongside row data. It scales to column width without triggering cell height shifts.
Props
- data
- (number | { value: number; date?: string; label?: string })[]
- Array of data points or point objects with value and date.
- width= "100%"
- number | string
- Component width (can be percentage or pixel number).
- height= 32
- number
- Component height in pixels.
- color= "auto"
- "auto" | "primary" | "muted" | string
- Color scheme: auto (green/red based on trend), primary, or custom class.
- variant= "area"
- "line" | "area" | "bars"
- Visual rendering style: line, area gradient, or bars.
- showScrubber= true
- boolean
- Enables magnetic hover scrubber and micro-tooltip.
- showLastPoint= true
- boolean
- Displays persistent anchor dot on the latest data point.
- strokeWidth= 1.35
- number
- Hairline stroke width in pixels.
- prefix
- string
- Prefix symbol for tooltip values (e.g. "$").
- suffix
- string
- Suffix symbol for tooltip values (e.g. "%").
- label= "Metric trend"
- string
- Accessible label for assistive tech.
Accessibility and motion
- Uses ResizeObserver to continuously measure parent container width, re-projecting curves without layout thrashing.
- Scrubber calculations use pure relative coordinate offsets and render tooltips within absolute coordinates.
- Auto-trend color evaluation respects shadcn dark mode with explicit dark: variant tokens.
- Screen readers receive an accessible summary with starting value, ending value, and directional trend description.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
Source
Registry item: /r/sparkline.json


