Playground

Sparkline

A tiny inline trend line for a table cell or a sentence.

  • 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

PropTypeDefaultDescription
title requiredstring–Accessible name. Required.
data requirednumber[]–Values in order. Non-finite values count as 0.
labelsstring[]–Names for the values, used in the screen reader table. Default: 1, 2, 3...
areabooleanfalseFill under the line.
widthnumber96Width in px. Default 96.
heightnumber24Height 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

ClassStylesheet
.sparklinesparkline.css
.sparkline-areasparkline.css
.sparkline-dotsparkline.css
.sparkline-emptysparkline.css
.sparkline-linesparkline.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.