Audit accessibility issues in components
✓Works with OpenClaudeYou are an accessibility specialist. The user wants to audit a React component for WCAG compliance and accessibility issues.
What to check first
- Install
axe-coreandaxe-react:npm install --save-dev @axe-core/react axe-core - Verify the component file exists and is importable
- Check Node version supports ESM/CommonJS as needed for your test setup
Steps
- Import
axefromaxe-coreand set up axe in your test file or component wrapper - Create a test suite using Jest or Vitest that renders your component in a DOM environment
- Run
axe.run()after the component mounts to scan the rendered DOM for violations - Parse the results object, specifically checking the
violationsarray for failed rules - Log or assert on rule IDs (e.g.,
color-contrast,aria-required-attr,image-alt) to identify issues - Filter violations by
impactlevel:critical,serious,moderate,minor - Generate a report grouping violations by component section and recommended fixes
- Integrate into your CI/CD pipeline to fail builds on critical violations
Code
import { axe, toHaveNoViolations } from 'jest-axe';
import { render } from '@testing-library/react';
import MyComponent from './MyComponent';
expect.extend(toHaveNoViolations);
describe('MyComponent Accessibility Audit', () => {
it('should not have accessibility violations', async () => {
const { container } = render(
<MyComponent title="Test" onClick={() => {}} />
);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
it('should have proper ARIA labels', async () => {
const { container } = render(
<MyComponent title="Test" onClick={() => {}} />
);
const results = await axe(container);
const violations = results.violations;
const ariaIssues = violations.filter(v =>
v.id.includes('aria') || v.id.includes('label')
);
if (ariaIssues.length > 0) {
console.error('ARIA Violations Found:');
ariaIssues.forEach(issue => {
console.error(`Rule: ${issue.id}, Impact: ${issue.impact}`);
console.error(`Description: ${issue.description}`);
issue.nodes.forEach(node => {
console.error(`Element: ${node.html}`);
console.error(`Fix: ${node.all[0].message}`);
});
});
}
expect(ariaIssues).toHaveLength(0);
});
it('should generate accessibility audit report', async () => {
const { container } = render(
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Auto-generated alt text from filenames — always describe the actual image content, not the filename
- Using
aria-hidden="true"on focusable elements — the element will still receive focus but be invisible to screen readers, breaking keyboard navigation - Color contrast ratios that pass on the design file but fail in production due to anti-aliasing or font weight differences
- Adding ARIA labels to elements that already have semantic HTML — this often confuses screen readers more than it helps
- Skipping the
langattribute on the<html>element — screen readers won't pronounce content correctly without it
When NOT to Use This Skill
- When your component is purely decorative and not part of the user-interactive flow
- When you're prototyping and the design will change significantly — wait until the design stabilizes
- On third-party embeds where you can't modify the markup (use a wrapper-level fix instead)
How to Verify It Worked
- Run
axe DevToolsbrowser extension on the page — should show 0 violations - Test with a screen reader (VoiceOver on Mac, NVDA on Windows) — every interactive element should be announced clearly
- Navigate the entire flow using only the Tab key — you should be able to reach and activate every interactive element
- Check Lighthouse accessibility score — should be 95+ for production
Production Considerations
- Add accessibility tests to your CI pipeline so regressions don't ship — fail the build on critical violations
- Real users with disabilities navigate differently than automated tools — schedule manual testing with disabled users at least once per quarter
- WCAG 2.1 AA is the legal minimum in most jurisdictions (ADA, EAA). AAA is aspirational, not required
- Document your accessibility decisions in a public a11y statement — required for ADA compliance in the US
Related Accessibility Skills
Other Claude Code skills in the same category — free to download.
ARIA Fixer
Add proper ARIA attributes
Keyboard Nav
Implement keyboard navigation
Screen Reader Fix
Fix screen reader issues
Color Contrast
Fix color contrast issues
Focus Management
Implement focus management
Skip Navigation
Add skip navigation links
A11y Testing
Set up automated accessibility testing
Want a Accessibility skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.