Sparkline
A tiny inline trend line for a table cell or a sentence.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native elements
- role=img with the required title as its name.
- A visually hidden table (table roles on spans, valid inside a paragraph) lists every value for screen readers.
- Decorative at a glance: it has no tooltip and no tab stops.
- Styles in one file:
sparkline.css
Import
import '@monoline/css';
import {Sparkline} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add sparkline
Usage
import {Sparkline} from '@monoline/react';
<p>Signups <Sparkline title="Signups, last 10 days" data={[3, 5, 4, 8, 6, 9, 12, 10, 14, 13]} /> up 18% this week.</p>
Examples
Inline
With area, wider
Flat and empty
Props
SparklineProps
| Prop | Type | Default | Description |
|---|---|---|---|
title required | string | – | Accessible name. Required. |
data required | number[] | – | Values in order. Non-finite values count as 0. |
labels | string[] | – | Names for the values, used in the screen reader table. Default: 1, 2, 3... |
area | boolean | false | Fill under the line. |
width | number | 96 | Width in px. Default 96. |
height | number | 24 | Height in px. Default 24. |
valueFormat | ((value: number) => string) | – | Format a value for the screen reader table. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.sparkline | sparkline.css |
.sparkline-area | sparkline.css |
.sparkline-dot | sparkline.css |
.sparkline-empty | sparkline.css |
.sparkline-line | sparkline.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.sparkline {
border-color: var(--accent);
}
Accessibility
- role=img with the required title as its name.
- A visually hidden table (table roles on spans, valid inside a paragraph) lists every value for screen readers.
- Decorative at a glance: it has no tooltip and no tab stops.