9

Our charts passed a visual review and failed an a11y audit hard: color-only encoding, no keyboard access, screen readers announcing a wall of unlabeled paths. Retrofitting was miserable, so I moved the requirements into the generation prompt.

The key was demanding a data-table fallback as a first-class deliverable (not a hack), a colorblind-safe palette with redundant encoding, and a described-summary of the trend. The model now produces charts that are legible to a screen reader and survive a contrast checker on the first pass.

Sharing the prompt. Would love pushback on whether the visually-hidden table is the right pattern versus a toggle.

THE PROMPT
Generate an accessible chart (SVG-based, framework-agnostic) that passes WCAG 2.1 AA. Treat accessibility as a primary deliverable, not an add-on:

1. Semantics: root svg with role='img' and an aria-label that SUMMARIZES the takeaway ('Revenue rose 18% from Jan to Jun, dipping in April'), not just 'a chart'. Decorative elements aria-hidden.
2. Data-table fallback: emit a real, visually-hidden <table> with the underlying data, associated with the chart, so screen readers get the numbers. This is required, not optional.
3. Color: use a colorblind-safe categorical palette AND a redundant channel (line dash pattern or direct labels) so nothing relies on hue alone. State the palette and why.
4. Contrast: every text/axis element must hit >= 4.5:1 (>= 3:1 for large); print the computed ratios for axis labels and the smallest text.
5. Keyboard: focusable data points (tabindex), arrow-key navigation between them, and a live-region announcement of the focused point's value.
6. Motion: any transition respects prefers-reduced-motion.

Before the code, output an accessibility checklist mapping each item above to how it's satisfied. Then the single-file implementation.
1aria-label that states the takeaway instead of 'chart' is such a low-effort, high-impact rule. A screen reader user gets the point in one sentence.docs_dora 1 month ago
add a comment

1 Answer

6

The visually-hidden table is the right default over a toggle: a toggle is one more thing to forget to test, and sighted keyboard users benefit from the table being always-there under the SVG anyway. One refinement: use aria-describedby to point the svg at the table's caption, and make the table itself sr-only with the standard clip pattern, not display:none (display:none removes it from the accessibility tree too).

THE PROMPT
Wire the chart to the data with aria-describedby referencing the table caption id. Hide the table with the sr-only clip technique (position:absolute; clip-path; 1px), never display:none or visibility:hidden, so it stays in the accessibility tree.

Your Answer