Accessible charts for the web
OpenChart gives every chart a text label and keyboard navigation by default. You still write the alt text, and this post shows how to test it.
OpenChart3 min read
Made with OpenChart. How to build this line chart
In 2020, a season played mostly without fans, NFL home teams won 49.8% of their games, the only season from 1999 to 2025 below half. A sighted reader sees that dip in the chart below at a glance. A screen reader user gets it only if the chart says it in text, and needs three more things to use the chart at all: access to the values, a way to explore from the keyboard, and meaning that does not depend on color.
This chart sets no accessibility options.
Made with OpenChart. How to build this line chart
{
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"data": [
{
"season": "1999",
"home_win_pct": 59.7
},
{
"season": "2000",
"home_win_pct": 55.6
},
{
"season": "2001",
"home_win_pct": 54.8
},
{
"season": "2002",
"home_win_pct": 58
},
{
"season": "2003",
"home_win_pct": 61.3
},
{
"season": "2004",
"home_win_pct": 56.6
},
// … 21 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "season",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "home_win_pct",
"type": "quantitative",
"scale": {
"domain": [
40,
65
],
"zero": false
},
"axis": {
"title": "Home team wins",
"format": ".0f",
"labelSuffix": "%",
"grid": true
}
}
},
"theme": {
"colors": {
"annotationRule": {
"light": "#6b6b66",
"dark": "#a3a39c"
}
}
},
"annotations": [
{
"type": "refline",
"y": 50,
"label": "Even odds",
"style": "dashed",
"labelPlacement": "start",
"labelAnchor": "top",
"labelOffset": {
"dx": 40
}
},
{
"type": "text",
"x": "2020",
"y": 49.8,
"text": "2020: 49.8%",
"anchor": "bottom",
"offset": {
"dx": 0,
"dy": 30
},
"connector": true
}
],
"chromeLayout": "subtract",
"chrome": {
"title": "NFL home teams won 59.7% of games in 1999 and 49.8% in 2020",
"subtitle": "Share of regular-season games won by the home team, 1999-2025. Ties count as half a win."
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 27 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"encoding": {
"x": {
"field": "season",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "home_win_pct",
"type": "quantitative",
"scale": {
"domain": [
40,
65
],
"zero": false
},
"axis": {
"title": "Home team wins",
"format": ".0f",
"labelSuffix": "%",
"grid": true
}
}
},
"theme": {
"colors": {
"annotationRule": {
"light": "#6b6b66",
"dark": "#a3a39c"
}
}
},
"annotations": [
{
"type": "refline",
"y": 50,
"label": "Even odds",
"style": "dashed",
"labelPlacement": "start",
"labelAnchor": "top",
"labelOffset": {
"dx": 40
}
},
{
"type": "text",
"x": "2020",
"y": 49.8,
"text": "2020: 49.8%",
"anchor": "bottom",
"offset": {
"dx": 0,
"dy": 30
},
"connector": true
}
],
"chromeLayout": "subtract",
"chrome": {
"title": "NFL home teams won 59.7% of games in 1999 and 49.8% in 2020",
"subtitle": "Share of regular-season games won by the home team, 1999-2025. Ties count as half a win."
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 27 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"encoding": {
"x": {
"field": "season",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "home_win_pct",
"type": "quantitative",
"scale": {
"domain": [
40,
65
],
"zero": false
},
"axis": {
"title": "Home team wins",
"format": ".0f",
"labelSuffix": "%",
"grid": true
}
}
},
"theme": {
"colors": {
"annotationRule": {
"light": "#6b6b66",
"dark": "#a3a39c"
}
}
},
"annotations": [
{
"type": "refline",
"y": 50,
"label": "Even odds",
"style": "dashed",
"labelPlacement": "start",
"labelAnchor": "top",
"labelOffset": {
"dx": 40
}
},
{
"type": "text",
"x": "2020",
"y": 49.8,
"text": "2020: 49.8%",
"anchor": "bottom",
"offset": {
"dx": 0,
"dy": 30
},
"connector": true
}
],
"chromeLayout": "subtract",
"chrome": {
"title": "NFL home teams won 59.7% of games in 1999 and 49.8% in 2020",
"subtitle": "Share of regular-season games won by the home team, 1999-2025. Ties count as half a win."
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 27 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"encoding": {
"x": {
"field": "season",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "home_win_pct",
"type": "quantitative",
"scale": {
"domain": [
40,
65
],
"zero": false
},
"axis": {
"title": "Home team wins",
"format": ".0f",
"labelSuffix": "%",
"grid": true
}
}
},
"theme": {
"colors": {
"annotationRule": {
"light": "#6b6b66",
"dark": "#a3a39c"
}
}
},
"annotations": [
{
"type": "refline",
"y": 50,
"label": "Even odds",
"style": "dashed",
"labelPlacement": "start",
"labelAnchor": "top",
"labelOffset": {
"dx": 40
}
},
{
"type": "text",
"x": "2020",
"y": 49.8,
"text": "2020: 49.8%",
"anchor": "bottom",
"offset": {
"dx": 0,
"dy": 30
},
"connector": true
}
],
"chromeLayout": "subtract",
"chrome": {
"title": "NFL home teams won 59.7% of games in 1999 and 49.8% in 2020",
"subtitle": "Share of regular-season games won by the home team, 1999-2025. Ties count as half a win."
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 27 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"encoding": {
"x": {
"field": "season",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "home_win_pct",
"type": "quantitative",
"scale": {
"domain": [
40,
65
],
"zero": false
},
"axis": {
"title": "Home team wins",
"format": ".0f",
"labelSuffix": "%",
"grid": true
}
}
},
"theme": {
"colors": {
"annotationRule": {
"light": "#6b6b66",
"dark": "#a3a39c"
}
}
},
"annotations": [
{
"type": "refline",
"y": 50,
"label": "Even odds",
"style": "dashed",
"labelPlacement": "start",
"labelAnchor": "top",
"labelOffset": {
"dx": 40
}
},
{
"type": "text",
"x": "2020",
"y": 49.8,
"text": "2020: 49.8%",
"anchor": "bottom",
"offset": {
"dx": 0,
"dy": 30
},
"connector": true
}
],
"chromeLayout": "subtract",
"chrome": {
"title": "NFL home teams won 59.7% of games in 1999 and 49.8% in 2020",
"subtitle": "Share of regular-season games won by the home team, 1999-2025. Ties count as half a win."
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
A screen reader meets it as a single role="img" with the label “Line chart showing NFL home teams won 59.7% of games in 1999 and 49.8% in 2020 from 1999 to 2025 (27 data points)”. The library builds that label from the chart type, your title, the date range and the point count. Treat it as a fallback: it reads awkwardly, and it carries the finding only as far as your title does.
Alt text
Set a11y.description and it replaces the generated label. Write the finding there in a sentence or two and leave out the chart type, which tells a listener nothing about the data.
The chart below does this. Its description gives the year synthetic opioids passed heroin, the peak and the drop since.
Made with OpenChart. How to build this line chart
{
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"a11y": {
"description": "Synthetic opioid overdose deaths passed heroin deaths in 2016, 19,500 to 15,551, and peaked at 74,829 in 2022. By 2025 they had fallen 49% from the peak, to 38,462."
},
"data": [
{
"year": "2015",
"drug": "Synthetic opioids",
"deaths": 9610
},
{
"year": "2015",
"drug": "Heroin",
"deaths": 13051
},
{
"year": "2016",
"drug": "Synthetic opioids",
"deaths": 19500
},
{
"year": "2016",
"drug": "Heroin",
"deaths": 15551
},
{
"year": "2017",
"drug": "Synthetic opioids",
"deaths": 28659
},
{
"year": "2017",
"drug": "Heroin",
"deaths": 15593
},
// … 16 more rows; Copy includes them
],
"encoding": {
"x": {
"field": "year",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {
"title": "Deaths, 12 months ending December",
"format": ",.0f",
"grid": true
}
},
"color": {
"field": "drug",
"type": "nominal",
"scale": {
"domain": [
"Synthetic opioids",
"Heroin"
]
}
},
"strokeDash": {
"field": "drug",
"type": "nominal"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
},
{
"light": "#b54d00",
"dark": "#f07a2b"
}
]
}
},
"legend": {
"show": false
},
"endpointLabels": {
"format": ",.0f"
},
"chromeLayout": "subtract",
"chrome": {
"title": "Synthetic opioids passed heroin in 2016 and peaked at 74,829 deaths in 2022",
"subtitle": "US overdose deaths involving each drug, 12 months ending December, 2015-2025"
}
}import { Chart } from "@opendata-ai/openchart-react";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"a11y": {
"description": "Synthetic opioid overdose deaths passed heroin deaths in 2016, 19,500 to 15,551, and peaked at 74,829 in 2022. By 2025 they had fallen 49% from the peak, to 38,462."
},
"encoding": {
"x": {
"field": "year",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {
"title": "Deaths, 12 months ending December",
"format": ",.0f",
"grid": true
}
},
"color": {
"field": "drug",
"type": "nominal",
"scale": {
"domain": [
"Synthetic opioids",
"Heroin"
]
}
},
"strokeDash": {
"field": "drug",
"type": "nominal"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
},
{
"light": "#b54d00",
"dark": "#f07a2b"
}
]
}
},
"legend": {
"show": false
},
"endpointLabels": {
"format": ",.0f"
},
"chromeLayout": "subtract",
"chrome": {
"title": "Synthetic opioids passed heroin in 2016 and peaked at 74,829 deaths in 2022",
"subtitle": "US overdose deaths involving each drug, 12 months ending December, 2015-2025"
}
};
export function Example() {
return <Chart spec={spec} />;
}
<script setup lang="ts">
import { Chart } from "@opendata-ai/openchart-vue";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"a11y": {
"description": "Synthetic opioid overdose deaths passed heroin deaths in 2016, 19,500 to 15,551, and peaked at 74,829 in 2022. By 2025 they had fallen 49% from the peak, to 38,462."
},
"encoding": {
"x": {
"field": "year",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {
"title": "Deaths, 12 months ending December",
"format": ",.0f",
"grid": true
}
},
"color": {
"field": "drug",
"type": "nominal",
"scale": {
"domain": [
"Synthetic opioids",
"Heroin"
]
}
},
"strokeDash": {
"field": "drug",
"type": "nominal"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
},
{
"light": "#b54d00",
"dark": "#f07a2b"
}
]
}
},
"legend": {
"show": false
},
"endpointLabels": {
"format": ",.0f"
},
"chromeLayout": "subtract",
"chrome": {
"title": "Synthetic opioids passed heroin in 2016 and peaked at 74,829 deaths in 2022",
"subtitle": "US overdose deaths involving each drug, 12 months ending December, 2015-2025"
}
};
</script>
<template>
<Chart :spec="spec" />
</template>
<script lang="ts">
import { Chart } from "@opendata-ai/openchart-svelte";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"a11y": {
"description": "Synthetic opioid overdose deaths passed heroin deaths in 2016, 19,500 to 15,551, and peaked at 74,829 in 2022. By 2025 they had fallen 49% from the peak, to 38,462."
},
"encoding": {
"x": {
"field": "year",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {
"title": "Deaths, 12 months ending December",
"format": ",.0f",
"grid": true
}
},
"color": {
"field": "drug",
"type": "nominal",
"scale": {
"domain": [
"Synthetic opioids",
"Heroin"
]
}
},
"strokeDash": {
"field": "drug",
"type": "nominal"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
},
{
"light": "#b54d00",
"dark": "#f07a2b"
}
]
}
},
"legend": {
"show": false
},
"endpointLabels": {
"format": ",.0f"
},
"chromeLayout": "subtract",
"chrome": {
"title": "Synthetic opioids passed heroin in 2016 and peaked at 74,829 deaths in 2022",
"subtitle": "US overdose deaths involving each drug, 12 months ending December, 2015-2025"
}
};
</script>
<Chart {spec} />
import { createChart } from "@opendata-ai/openchart-vanilla";
import type { ChartSpec } from "@opendata-ai/openchart-core";
import "@opendata-ai/openchart-core/styles.css";
const data = [/* 22 rows; Copy includes them */];
const spec: ChartSpec = {
data,
"mark": {
"type": "line",
"strokeWidth": 2.5,
"interpolate": "linear"
},
"a11y": {
"description": "Synthetic opioid overdose deaths passed heroin deaths in 2016, 19,500 to 15,551, and peaked at 74,829 in 2022. By 2025 they had fallen 49% from the peak, to 38,462."
},
"encoding": {
"x": {
"field": "year",
"type": "temporal",
"axis": {
"format": "%Y"
}
},
"y": {
"field": "deaths",
"type": "quantitative",
"axis": {
"title": "Deaths, 12 months ending December",
"format": ",.0f",
"grid": true
}
},
"color": {
"field": "drug",
"type": "nominal",
"scale": {
"domain": [
"Synthetic opioids",
"Heroin"
]
}
},
"strokeDash": {
"field": "drug",
"type": "nominal"
}
},
"theme": {
"colors": {
"categorical": [
{
"light": "#0e7490",
"dark": "#22a3c4"
},
{
"light": "#b54d00",
"dark": "#f07a2b"
}
]
}
},
"legend": {
"show": false
},
"endpointLabels": {
"format": ",.0f"
},
"chromeLayout": "subtract",
"chrome": {
"title": "Synthetic opioids passed heroin in 2016 and peaked at 74,829 deaths in 2022",
"subtitle": "US overdose deaths involving each drug, 12 months ending December, 2015-2025"
}
};
const container = document.getElementById("chart");
if (!container) throw new Error('Add <div id="chart"></div> to the page first.');
createChart(container, spec);
Data table and keyboard navigation
Next to every live chart the library builds a hidden HTML table of its data, and a screen reader can read it. Its column headers are your field names, so name your fields for a person. The football chart’s table opens with season and home_win_pct. Its numbers are the raw values, unformatted. If you supply your own table, a11y: { table: false } turns the generated one off. A visible data table beside the chart serves readers who want to look up exact values.
The chart container takes keyboard focus. On line charts the left and right arrow keys step from one x position to the next, the tooltip lists every series at that position, and Escape closes it. In the overdose chart, focus starts at 2015, and two presses of the right arrow reach 2017, where the tooltip reads 28,659 for synthetic opioids and 15,593 for heroin. To announce each step in your own live region, pass onMarkFocus when you mount the chart. The interaction page lists the other handlers.
Color contrast and dash patterns
The overdose chart gives each line a color, a dash pattern and a name at its right end, so a reader who cannot tell orange from teal can still tell the lines apart. Bars and areas can take fillPattern: "auto" to add hatching. The colorblind palettes post covers choosing the colors themselves.
Pass dev: true to compileChart while you build and the engine warns when adjacent series fall under the 3:1 contrast minimum for graphics. Two pale blues, #9ecae1 and #a6d0e8, produced “1.07:1 contrast” and a suggested replacement. The color guide has the palette options.
Static SVG charts
renderStaticSVG returns an SVG with role="img" and the same label, but no hidden table and no keyboard navigation. If you embed static charts, write the finding as a sentence beside the chart and supply the table yourself.
Testing
Select the chart’s role="img" element in your browser’s inspector and read its aria-label. Look for the hidden table beside it, named by its oc-sr-only wrapper. Tab to the chart, put the mouse aside and press the arrow keys. Reading the DOM doesn’t tell you how a chart sounds, so listen to it in VoiceOver or NVDA before you ship.
The spec
a11y.description holds the alternative text. theme.colors.categorical gives each line a light and a dark color, and each one passes 4.5:1 as end-label text on its page. In encoding, color and strokeDash both map the drug field, so each line differs in hue and in dash. endpointLabels writes the series names at the line ends, and legend: { show: false } drops the legend they replace.
The accessibility docs map each option to the WCAG success criteria it helps meet.