Accessibility
Keyboard, screen readers, contrast, and what we test.
Accessibility is part of each component, not an option. A chart works from the keyboard, carries its data as a table for screen readers, and holds still when the visitor asks for less motion. Your part is small: give every chart a label, and keep your theme's colours readable. This page says what is built in, what is tested, and where the limits are.
Charts and the keyboard
A chart with a reading cursor is one tab stop, however many points it has. Focus it and the cursor appears, with the same readout a pointer gets.
| Keys | Action |
|---|---|
| Tab | Focus the chart. The cursor goes to the latest point. |
| → or ↑ | Move the cursor to the next point. |
| ← or ↓ | Move the cursor to the previous point. |
| Home | Jump to the first point. |
| End | Jump to the last point. |
| Esc | Hide the cursor. The chart keeps focus. |
Moving focus away from the chart hides the cursor.
- Screen readers meet the chart as a slider named after your
label, followed by “Use the arrow keys to read values.” As the cursor moves, the point is read as its name and value: “Tue: 180”. - Pointer. The whole plot is the target. The cursor snaps to the nearest point, so nobody has to hit a 2 px line.
- Touch. Touch or drag sideways to read values. A vertical drag still scrolls the page.
- Focus is always visible: a 2 px ring in your theme's
--ringcolour.
Three charts differ from the table:
- The calendar heatmap is a grid of days. ← and → move the cursor by a week, ↑ and ↓ by a day.
- The line chart's legend adds one button for each series, which shows or hides it.
- The live chart has no cursor and is not a tab stop. It is one image whose text gives the latest, lowest and highest value.
Your part
Pass a label that says what is measured, with its unit if it has one: “Revenue”, “Response time in milliseconds”. It names the chart for screen readers and captions the data table. It is required.
Hidden data tables
Every chart with values also renders a real <table> that only assistive technology sees. Its caption is the chart's label. It has one row per point, with the values formatted exactly as they are on screen. A missing value is a dash.
The table is hidden with Tailwind's sr-only class, so it costs no space and needs no setup. A screen reader user can read the whole series without touching the cursor.
Meters, sparklines and numbers
- A sparkline is exposed as a single image whose text states the trend in words. A sparkline labelled “Revenue” is read as “Revenue: starts at 4.2K, ends at 5.1K, low 3.9K, high 5.3K”.
- A ring meter, a gauge and a usage meter are exposed as meters, named after your
label. The reading is spoken with its state: a ring meter in its warning state is read as “82 of 100, warning”. - State is never colour alone. A meter that turns from normal to warning also says so in words.
- Animated numbers give screen readers the real value at once, as ordinary text. The rolling digits are hidden from them. An animated number is deliberately not a live region: a figure that changes many times a second must not be read out each time.
When a change does matter, announce it yourself, once, in words:
<AnimatedNumber value={total} />
<p className="sr-only" aria-live="polite">
{done ? `Import finished: ${total} rows` : ""}
</p>Contrast
Components draw with your theme's colours, so the contrast is your theme's. The targets are the usual ones:
- Lines, bars and other marks: 3:1 or better against
--background. - Text, including axis labels in
--muted-foreground: 4.5:1 or better.
Check each chart colour in both themes. Two things are built in to help:
- A mark that sits on another mark has a 2 px ring in the background colour, so it stays separate whatever the two colours are.
- Series colours are given out in a fixed order and never repeat. Still, do not rely on colour to tell series apart: name them in a legend or beside the line.
Target size
Anything a pointer operates is at least 24 by 24 CSS pixels. For charts the target is the whole plot area. Small marks never have to be hit directly. On touch screens, charts leave vertical scrolling to the page, so a chart never traps a scroll.
Motion and sound
- With the system's reduced-motion setting on, every component shows its final state at once. Motion has the details.
- Sound is off until the visitor turns it on, and nothing is ever conveyed by sound alone. Sound has the details.
What is tested automatically
Every component in the catalogue goes through the same checks in a real browser before it is published:
- The page renders with no errors in the console.
- An axe scan finds no serious or critical violations, in the light and in the dark theme.
- With reduced motion, the component's markup matches its settled state straight after it mounts, and nothing moves afterwards.
- Nothing on the page shifts while the component loads, animates and replays.
- New data redraws without errors.
- A chart cursor has a name, answers Home, → and End with a new reading each time, and the data table is present.
Known limits
Stated plainly, so you can plan around them:
- An automated scan finds only some accessibility problems. The components have not had an independent audit, and have not been tested with every screen reader and browser pair.
- The checks run against this site's theme. With your theme, contrast is yours to check.
- A chart is announced as a slider, because that is the standard role for stepping through values with the arrow keys. Some visitors will not expect a chart there. The data table is the complete alternative.
- A sparkline has no cursor and no table. Its summary gives the start, end, low and high only. If every value matters, show the numbers elsewhere too.
- On a narrow chart, not every point's name fits on the axis. Names are thinned to what fits; the cursor and the table always have all of them.
- Windows high-contrast mode (forced colours) and right-to-left layouts are not tested yet.
- Axis and readout text inside charts is 12 px. It follows the browser's zoom, and does not grow with the size of the chart.