a11y-warden

Warden · privacy & compliance

a11y-warden

WCAG 2.2 accessibility audit of static HTML for CI, with a baseline so you can adopt it on an existing site and only fail on new problems.

npm i -D @mrlouiswright/a11y-warden

Published to GitHub Packages: add @mrlouiswright:registry=https://npm.pkg.github.com to .npmrc first (installing needs a token with read:packages).

What it checks

  • Text alternatives (1.1.1)missing alt, file-name or placeholder alt (IMG_1234.png, "image of…"), unnamed <svg role="img">, <input type="image">.
  • Names and labels (1.3.1, 2.4.4, 4.1.2)form controls without label/aria-label/aria-labelledby/title (placeholders do not count), buttons and links without accessible names, generic link text, iframes without title.
  • Contrast (1.4.3)inline color against the nearest inline background-color (or a configurable default), with the 3:1 large-text exception.
  • Structure (1.3.1, 2.4.1, 2.4.2, 3.1.1)<html lang>, <title>, a single <main>, data tables without <th>.
  • ARIA and focus (2.4.3, 2.4.7, 4.1.2)invalid roles, aria-labelledby/describedby/controls and <label for> pointing at missing ids, duplicate referenced ids, aria-hidden containing focusable elements, positive tabindex, inline outline: none.
  • Zoom and media (1.4.2, 1.4.4)viewport that disables zoom, media that autoplays with sound and no controls.
  • Baseline--update-baseline records current findings; later runs ignore them and report only new ones. Hidden content (hidden, aria-hidden) is skipped.

Quick usage

CLI

npx a11y-warden dist
npx a11y-warden dist --update-baseline   # record existing issues once
npx a11y-warden dist --baseline .a11y-baseline.json --fail-on medium
npx a11y-warden _site --format sarif > a11y.sarif

API

import { check, contrastRatio, parseColor } from "a11y-warden";
const report = check("dist");
contrastRatio(parseColor("#767676"), parseColor("#fff")); // 4.54

Every option is documented in the a11y-warden docs.

CI / GitHub Action

permissions:
  contents: read
  security-events: write   # only needed for the SARIF upload
jobs:
  a11y-warden:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
        with: { persist-credentials: false }
      - run: npm ci && npm run build   # produce the static site first
      - uses: MrLouisWright/a11y-warden@v1
        with:
          path: dist
          fail-on: high
          sarif: a11y-warden.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with: { sarif_file: a11y-warden.sarif }