WCAG Contrast
Storybook addon: a Contrast panel that checks a story's colour pairs against WCAG 2.2 (AA/AAA). By Nexfield Academy.
Storybook addon: WCAG Contrast
A Contrast panel for Storybook that checks the colour pairs of each story against WCAG 2.2: preview, contrast ratio and a pass/fail verdict for normal text, large text and UI components (icons, borders, focus rings).
Made by Nexfield Academy, an online school of UX/UI, graphic and web design.

Install
npm install -D storybook-addon-wcag-contrast
// .storybook/main.js
export default {
addons: ['storybook-addon-wcag-contrast'],
};
Usage
Declare the colour pairs a component uses in the story (or component) parameters:
export default {
component: Button,
parameters: {
wcagContrast: {
level: 'AA', // or 'AAA'
pairs: [
{ name: 'Label', foreground: '#ffffff', background: '#0040ff' },
{ name: 'Hint', foreground: '#767676', background: '#ffffff' },
{ name: 'Heading', foreground: '#555555', background: '#ffffff', size: 'large' },
{ name: 'Focus ring', foreground: '#0040ff', background: '#ffffff', size: 'ui' },
],
},
},
};
Open the Contrast tab in the addon panel. Colours can be #hex, rgb() or hsl(); translucent colours are laid over the background before measuring.
Thresholds (WCAG 2.2)
| Check | AA | AAA |
|---|---|---|
| Normal text | 4.5:1 | 7:1 |
| Large text (24 px, or 18.66 px bold) | 3:1 | 4.5:1 |
| UI components (WCAG 1.4.11) | 3:1 | 3:1 |
The ratio is rounded down to two decimals before comparing, so 4.49:1 never passes as 4.5:1.
Related tools
- Online contrast checker with a colour picker
- VS Code extension, Gatsby plugin, Strapi field, Docker CLI
Want to learn how designers choose accessible colours? See the UX/UI design course at Nexfield Academy.
Compatibility
Storybook 9 and newer (tested on Storybook 11.0 RC with React + Vite).
License
MIT
- nexfield.academy