--- name: a11y description: Master accessibility audit skill that scans every screen with axe-core, tests keyboard navigation, checks focus visibility, audits ARIA and semantic structure, then fixes every violation from critical down to minor. Works screen by screen in priority order with visual and programmatic verification. Use when user wants to fix accessibility issues, meet WCAG 2.1 AA, improve keyboard nav, or invokes /a11y. --- # /a11y — Master Accessibility Audit Finds and fixes every accessibility violation across the entire app. Works programmatically (axe-core) and visually (keyboard screenshots), from critical to minor, screen by screen. Full WCAG quick-reference and fix patterns: [WCAG.md](WCAG.md) --- ## Phase 0 — Environment Setup ### 0a. Check / start dev server ```bash curl -s --max-time 2 -o /dev/null -w "%{http_code}" http://localhost:3000 ``` If not `200`, find and start the dev command, then wait: ```bash until curl -s --max-time 2 http://localhost:3000 > /dev/null 2>&1; do sleep 1; done && echo "ready" ``` ### 0b. Find source root ```bash find . -type d -name "src" \ -not -path "*/node_modules/*" \ -not -path "*/.next/*" \ -not -path "*/dist/*" \ -not -path "*/.turbo/*" \ | head -1 ``` If no `src/`: `find . -type d -name "app" -not -path "*/node_modules/*" -not -path "*/.next/*" | head -1` Use the result as `` throughout. ### 0c. Verify axe-core ```bash find . -path "*/axe-core/package.json" -not -path "*/node_modules/.cache/*" 2>/dev/null | head -1 ``` If not found: install it (dev dependency only): ```bash pnpm add -D axe-core 2>/dev/null || npm install -D axe-core 2>/dev/null || yarn add -D axe-core ``` Resolve the axe bundle path for later injection: ```bash find . -path "*/axe-core/axe.min.js" -not -path "*/node_modules/.cache/*" 2>/dev/null | head -1 ``` Store this as ``. ### 0d. Write the scan script Write to the **project root** (needs node_modules). Deleted in Phase 4. **`_a11y_scan.mjs`:** ```js import { chromium } from '@playwright/test'; import { mkdirSync, writeFileSync } from 'fs'; import { createRequire } from 'module'; const require = createRequire(import.meta.url); const get = (f) => { const i = process.argv.indexOf(f); return i !== -1 ? process.argv[i+1] : null; }; const url = get('--url'); const name = get('--name') ?? 'screen'; const width = parseInt(get('--width') ?? '1280'); const height = parseInt(get('--height') ?? '900'); const auth = get('--auth'); const screenshot = get('--screenshot') ?? `/tmp/a11y-${name}.png`; const report = get('--report') ?? `/tmp/a11y-${name}.json`; if (!url) { console.error('--url required'); process.exit(1); } mkdirSync('/tmp/a11y', { recursive: true }); const axePath = (() => { try { return require.resolve('axe-core'); } catch { console.error('axe-core not found — run: pnpm add -D axe-core'); process.exit(1); } })(); const browser = await chromium.launch(); const context = await browser.newContext({ viewport: { width, height }, ...(auth ? { storageState: auth } : {}), }); const page = await context.newPage(); try { await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 }); } catch { await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 }); } // Inject axe-core from local node_modules await page.addScriptTag({ path: axePath }); // Run axe scan const results = await page.evaluate(async () => { const r = await window.axe.run(document, { runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'best-practice'] }, }); return { violations: r.violations.map(v => ({ id: v.id, impact: v.impact, description: v.description, help: v.help, helpUrl: v.helpUrl, nodes: v.nodes.map(n => ({ html: n.html, target: n.target, failureSummary: n.failureSummary })), })), incomplete: r.incomplete.length, passes: r.passes.length, }; }); await page.screenshot({ path: screenshot, fullPage: true }); await browser.close(); writeFileSync(report, JSON.stringify(results, null, 2)); const counts = { critical: 0, serious: 0, moderate: 0, minor: 0 }; for (const v of results.violations) counts[v.impact] = (counts[v.impact] ?? 0) + 1; console.log(`saved: ${screenshot}`); console.log(`report: ${report}`); console.log(`violations: critical=${counts.critical} serious=${counts.serious} moderate=${counts.moderate} minor=${counts.minor}`); console.log(`passes: ${results.passes} | incomplete: ${results.incomplete}`); ``` **Usage:** ```bash node _a11y_scan.mjs --url http://localhost:3000 --name home node _a11y_scan.mjs --url http://localhost:3000/dashboard --name dashboard --auth /tmp/uiux-auth-state.json node _a11y_scan.mjs --url http://localhost:3000/settings --name settings --width 375 --height 812 ``` **After every scan: read the JSON report and the screenshot.** ### 0e. Write the keyboard navigation script Write to the **project root**. Deleted in Phase 4. **`_a11y_keyboard.mjs`:** ```js import { chromium } from '@playwright/test'; import { mkdirSync } from 'fs'; const get = (f) => { const i = process.argv.indexOf(f); return i !== -1 ? process.argv[i+1] : null; }; const url = get('--url'); const name = get('--name') ?? 'screen'; const width = parseInt(get('--width') ?? '1280'); const height = parseInt(get('--height') ?? '900'); const auth = get('--auth'); const maxTabs = parseInt(get('--max-tabs') ?? '30'); if (!url) { console.error('--url required'); process.exit(1); } mkdirSync('/tmp/a11y', { recursive: true }); const browser = await chromium.launch(); const context = await browser.newContext({ viewport: { width, height }, ...(auth ? { storageState: auth } : {}), }); const page = await context.newPage(); try { await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 }); } catch { await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 }); } const issues = []; // Check for skip link as first tab stop await page.keyboard.press('Tab'); const skipLink = await page.evaluate(() => { const el = document.activeElement; if (!el || el === document.body) return null; return { tag: el.tagName, text: el.textContent?.trim(), href: el.getAttribute('href') }; }); const hasSkipLink = skipLink?.text?.toLowerCase().includes('skip') && skipLink?.href?.startsWith('#'); if (!hasSkipLink) issues.push({ type: 'missing-skip-link', detail: 'First Tab stop is not a "Skip to main content" link' }); // Tab through interactive elements const focusLog = []; for (let i = 0; i < maxTabs; i++) { await page.keyboard.press('Tab'); const focusInfo = await page.evaluate(() => { const el = document.activeElement; if (!el || el === document.body) return null; const style = getComputedStyle(el); const rect = el.getBoundingClientRect(); // Capture focused styles const focusedBorder = style.borderColor; const focusedBackground = style.backgroundColor; // Briefly blur to capture unfocused styles, then refocus el.blur(); const blurStyle = getComputedStyle(el); const blurBorder = blurStyle.borderColor; const blurBackground = blurStyle.backgroundColor; el.focus(); return { tag: el.tagName, role: el.getAttribute('role'), ariaLabel: el.getAttribute('aria-label'), text: el.textContent?.trim().slice(0, 60), outlineWidth: style.outlineWidth, outlineStyle: style.outlineStyle, boxShadow: style.boxShadow, hasBorderChange: focusedBorder !== blurBorder, hasBackgroundChange:focusedBackground !== blurBackground, width: Math.round(rect.width), height: Math.round(rect.height), }; }); if (!focusInfo) break; // Detect focus visibility via outline, box-shadow, or meaningful border/background change. // Compare against a snapshot of the element's non-focused style by briefly blurring and refocusing. const hasVisibleFocus = ( (focusInfo.outlineStyle !== 'none' && focusInfo.outlineWidth !== '0px') || (focusInfo.boxShadow && focusInfo.boxShadow !== 'none') || focusInfo.hasBorderChange || focusInfo.hasBackgroundChange ); const hasName = !!(focusInfo.ariaLabel || focusInfo.text); const isTiny = focusInfo.width < 44 || focusInfo.height < 44; if (!hasVisibleFocus) issues.push({ type: 'no-focus-visible', element: focusInfo.tag, text: focusInfo.text }); if (!hasName) issues.push({ type: 'missing-accessible-name', element: focusInfo.tag }); if (isTiny) issues.push({ type: 'small-tap-target', element: focusInfo.tag, text: focusInfo.text, size: `${focusInfo.width}×${focusInfo.height}` }); focusLog.push({ ...focusInfo, hasVisibleFocus, hasName }); } // Screenshot after keyboard traversal (last focused state) await page.screenshot({ path: `/tmp/a11y/${name}-keyboard.png`, fullPage: false }); await browser.close(); console.log(`keyboard screenshot: /tmp/a11y/${name}-keyboard.png`); console.log(`tab stops visited: ${focusLog.length}`); if (issues.length) { console.log('issues found:'); issues.forEach(i => console.log(' -', JSON.stringify(i))); } else { console.log('no keyboard issues found'); } ``` **Usage:** ```bash node _a11y_keyboard.mjs --url http://localhost:3000 --name home node _a11y_keyboard.mjs --url http://localhost:3000/dashboard --name dashboard --auth /tmp/uiux-auth-state.json --max-tabs 50 ``` ### 0f. Handle auth-protected screens ```bash ls /tmp/uiux-auth-state.json /tmp/animate-auth-state.json /tmp/copy-auth-state.json 2>/dev/null | head -1 ``` If found, pass `--auth ` to all script calls for protected routes. If not found and protected screens exist, write `_a11y_auth.mjs` to the project root: ```js import { chromium } from '@playwright/test'; const { TEST_EMAIL, TEST_PASSWORD, LOGIN_URL, SUCCESS_URL } = process.env; if (!TEST_EMAIL || !TEST_PASSWORD) { console.error('Set TEST_EMAIL and TEST_PASSWORD'); process.exit(1); } const browser = await chromium.launch(); const page = await browser.newPage(); await page.goto(LOGIN_URL ?? 'http://localhost:3000/sign-in'); await page.fill('input[type="email"]', TEST_EMAIL); await page.fill('input[type="password"]', TEST_PASSWORD); await page.click('button[type="submit"]'); await page.waitForURL(SUCCESS_URL ?? '**/dashboard**', { timeout: 15000 }); await page.context().storageState({ path: '/tmp/a11y-auth-state.json' }); await browser.close(); console.log('saved → /tmp/a11y-auth-state.json'); ``` --- ## Phase 1 — Accessibility Audit ### 1a. Find all screens Every `page.tsx` in App Router, every page in Pages Router, modals, drawers, auth flows, settings, onboarding. List each with its route. ### 1b. Run axe scan on every screen For each screen, run at **both** desktop and mobile viewports. Tap target failures only appear at mobile. ```bash node _a11y_scan.mjs --url http://localhost:3000 --name -desktop node _a11y_scan.mjs --url http://localhost:3000 --name -mobile --width 375 --height 812 ``` Read both JSON reports and both screenshots. Group violations by impact: - **Critical** — `impact: "critical"` — content inaccessible to assistive tech - **Serious** — `impact: "serious"` — major barrier, usually WCAG AA failure - **Moderate** — `impact: "moderate"` — degrades the experience - **Minor** — `impact: "minor"` — best-practice violation ### 1c. Run keyboard nav test on every screen For each screen, run `_a11y_keyboard.mjs`. Read stdout for issues. Read the keyboard screenshot. ```bash node _a11y_keyboard.mjs --url http://localhost:3000 --name ``` Check manually from the output: - Is the first Tab stop a skip link? - Do all interactive elements have a visible focus ring? - Do all buttons and links have accessible names? - Are all tap targets ≥44×44px? ### 1d. Code-level scan for structural issues ```bash SRC= # Images without alt grep -rn " →