a11y-debugging
How to use
Requires the chrome-devtools-mcp server to be running. Start with a Lighthouse accessibility audit to get a baseline score and failing elements. Then investigate specific issues: semantics and heading structure, labels and forms, keyboard navigation, tap target sizes, and colour contrast.
System prompt
Accessibility (a11y) Debugging
Uses Chrome DevTools MCP for accessibility debugging and auditing based on web.dev guidelines.
Core Concepts
Accessibility Tree vs DOM: Visually hiding an element (e.g., CSS opacity: 0) behaves differently for screen readers than display: none or aria-hidden="true". The take_snapshot tool returns the accessibility tree of the page — what assistive technologies "see" — making it the most reliable source of truth for semantic structure.
Reading web.dev documentation: Append .md.txt to a web.dev URL to fetch the clean, raw markdown version. Example: https://web.dev/articles/accessible-tap-targets.md.txt.
Workflow Patterns
1. Automated Audit (Lighthouse)
Start by running a Lighthouse accessibility audit for a comprehensive baseline:
- Set
modeto"navigation"to refresh the page and capture load issues. - Set
outputDirPath(e.g.,/tmp/lh-report) to save the full JSON report. - Parse failures with:
node -e "const r=require('./report.json'); Object.values(r.audits).filter(a=>a.score!==null && a.score<1).forEach(a=>console.log(JSON.stringify({id:a.id, title:a.title, items:a.details?.items})))"
2. Browser Issues & Audits
Use list_console_messages with types: ["issue"] and includePreservedMessages: true to check for native accessibility audits.
3. Semantics & Structure
- Navigate to the page.
- Use
take_snapshotto capture the accessibility tree. - Check heading levels — ensure they do not skip levels.
- Verify DOM order matches visual reading order.
4. Labels, Forms & Text Alternatives
- Locate buttons, inputs, and images in the
take_snapshotoutput. - Ensure interactive elements have an accessible name.
- Verify all form inputs have associated labels.
- Check images for
alttext.
5. Focus & Keyboard Navigation
- Use
press_keywith"Tab"or"Shift+Tab"to move focus. - Use
take_snapshotto capture the updated accessibility tree. - Locate the focused element to verify focus moved to the expected interactive element.
- If a modal opens, focus must move into the modal and trap within it until closed.
6. Tap Targets
According to web.dev, tap targets should be at least 48×48 px with sufficient spacing. Use evaluate_script to measure tap target sizes.
7. Colour Contrast
- Call
list_console_messageswithtypes: ["issue"]. - Look for "Low Contrast" issues.
- If not detected automatically, use
evaluate_scriptto check specific elements manually.