# How to audit reference docs for keyboard and screen reader access

> Scan every page type of a rendered API reference with pa11y-ci, gate a Lighthouse score, list renderer bugs with an owner and an issue, and script the keyboard pass.

Source: https://voxgig.com/howto/audit-reference-docs-for-accessibility

- Audience: platform-team
- Level: intermediate
- Verified: 2026-11-30
- Published: 2026-11-30

## Short answer

Serve the built reference locally and run pa11y-ci with its axe runner over a fixed list: the landing page, one operation, the search box, and the try-it console. Fail the build on any finding not in an allowlist that names an owner and an upstream issue. Gate a Lighthouse CI accessibility score per page. Then tab through it, expand a schema, and read one operation with a screen reader.

---
## You will need

Node 22 or later, a built reference site you can serve locally, Chromium, and a screen reader for
the manual pass. Verified 2026-11-30 against Node 22.23.5, pa11y-ci 5.0.0 with pa11y 10.0.0 and
its axe-core 4.13.0, `@lhci/cli` 0.16.1 with Lighthouse 13.6.0, and `swagger-ui-dist` 5.36.0.
The keyboard pass ran in Chromium through Playwright 1.63.0. The `engines` field of pa11y-ci asks
for Node 22.13 or later, and that of `@lhci/cli` for 22.19 or later.

## Approaches compared

| Approach | When it fits | What it costs you | When to pick something else |
| --- | --- | --- | --- |
| [`@axe-core/cli`](https://github.com/dequelabs/axe-core-npm/tree/develop/packages/cli) | A list of URLs to scan as they load, with `--exit` to fail CI | A ChromeDriver that matches your browser, and no way to open search or click try-it first | The states you must scan only exist after a click |
| [A manual keyboard and screen reader pass](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html) | Focus order, focus loss, and what a control announces | Time from a person on every release, so it runs on releases, not pull requests | You need a check on every pull request |
| [Lighthouse CI](https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md) | One score per page that a pull request can be held to | A subset of axe rules, so a score of 1 can hide a finding | You need every axe rule or a named list of findings |
| [pa11y-ci](https://github.com/pa11y/pa11y-ci) | Scanning states behind a click or a typed query with `actions`, on every pull request | Dozens of renderer findings you cannot fix, so it needs an allowlist from day one | A one-off audit, where a single axe run reads faster |

The scanners are cheap and run everywhere, but they read markup, not behavior. Lighthouse turns
a page into one number you can gate on, and that number leaves out rules the scanners run.
Only a keyboard pass, by a person or a script, finds focus that disappears, and only a screen
reader user hears what a button announces. That pass costs time on every release.

## Scan every page type, not the page you wrote

The URL list is fixed and committed, so a scan that skips a page type is a broken run rather
than a quiet pass. Search and try-it are states of the reference page, reached with
[pa11y actions](https://github.com/pa11y/pa11y#actions):

```json title="urls.json"
[
  { "name": "landing", "path": "/" },
  { "name": "operation", "path": "/reference.html#/pets/listPets" },
  { "name": "search", "path": "/reference.html", "actions": ["set field input.operation-filter-input to pets", "wait for element .opblock-tag-section to be visible"] },
  { "name": "try-it", "path": "/reference.html#/pets/getPet", "actions": ["click element #operations-pets-getPet .try-out__btn", "wait for element #operations-pets-getPet .execute to be visible"] }
]
```

`record.sh` serves the site from 127.0.0.1 with Swagger UI rendering the reference, runs
pa11y-ci with `"runners": ["axe"]`, and trims the JSON to a rule id and a selector per finding.
`audit.mjs` holds that record to the list and to the allowlist:

```bash
node audit.mjs records/pa11y-before.json
```

```text output
records/pa11y-before.json: pa11y-ci 5.0.0, pa11y 10.0.0, axe-core 4.13.0
  landing      1 findings,   0 known, 1 new
    new: scrollable-region-focusable at html > body > main > pre
  operation   34 findings,  34 known, 0 new
  search      20 findings,  20 known, 0 new
  try-it      30 findings,  30 known, 0 new
  allowed with no upstream issue yet: aria-prohibited-attr, aria-label on the div that wraps the copy-path button, owner docs-platform
result: 1 new finding, fail
```

The hand-written page has one finding. The three renderer pages have 84 between them, from
contrast, a summary button that holds the copy-path control, and two selects with no name.

## Allowlist the renderer, with an owner and a link

Turning the check off throws away the one finding you can fix. Each known renderer issue gets a
rule id, a selector pattern, an owner, and the upstream issue it waits on:

```json title="known-issues.json"
  {
    "rule": "select-name",
    "where": "^#operations-.* > select$",
    "what": "the enum select in a parameter row",
    "owner": "docs-platform",
    "upstream": "https://github.com/swagger-api/swagger-ui/issues/8092"
  },
  {
    "rule": "aria-prohibited-attr",
    "where": "^#operations-[A-Za-z0-9_-]+ > div(:nth-child\\(1\\))? > div$",
    "what": "aria-label on the div that wraps the copy-path button",
    "owner": "docs-platform",
    "searched": "https://github.com/swagger-api/swagger-ui/issues?q=copy+path+to+clipboard"
  }
]
```

A search of the Swagger UI tracker found no issue for the last entry, so it carries the search
instead, and every run prints it until somebody files one. An entry with neither link is refused.
So is an entry that matches nothing in a run of the whole list, which is how a fixed issue leaves.
The allowlist belongs to one renderer at one version. Its patterns match the selectors of Swagger UI,
so a change of renderer starts the list again.

## Gate a Lighthouse score per page

The `assertMatrix` option of Lighthouse CI sets a budget per URL pattern in `lighthouserc.json`: 1 for the
landing page and 0.87, the score the renderer got on the day, for the reference. A pull request that
lowers either fails `lhci assert`. The audits that scored zero include `heading-order`.[^1]

```bash
node lighthouse.mjs records/lighthouse-before.json
```

```text output
records/lighthouse-before.json: @lhci/cli 0.16.1, lighthouse 13.6.0
  landing    score 1.00  zero: none
  operation  score 0.87  zero: color-contrast, heading-order, select-name, target-size, td-has-header
  lhci assert exit status: 0 (budget held)
```

That is the unfixed landing page scoring 1. Lighthouse 13.6.0
[turns off](https://github.com/GoogleChrome/lighthouse/blob/v13.6.0/core/gather/gatherers/accessibility.js#L70-L74)
`scrollable-region-focusable` and `nested-interactive` in the axe run it makes, so the landing page
finding never reaches its score.

## Walk it with a keyboard

`record/keyboard.mjs` tabs through the site in Chromium and records each focus stop with the role
and name Chromium computes:

```bash
node show.mjs keyboard-after
```

```text output
landing: 5 Tab stops before focus leaves the page
  a: link "Pets API"
  a: link "Reference"
  a: link "reference"
  pre: group "List the first page of pets with a sandbox key:"
  body (nothing focused)
landing: the code sample is a Tab stop: true
reference: 6 Tab stops to the first operation
  a: link "/openapi.json"
  select: combobox
  input: textbox "Filter by tag or path"
  a: link "pets"
  button: button "Collapse operation" [expanded] (aria-expanded=true)
  button: button "GET /v1/pets List pets" (aria-expanded=false)
after Enter on the operation, focus is on: button: button "GET /v1/pets List pets" [expanded] (aria-expanded=true)
reference: 30 more Tab stops to the Pet schema
after Enter on the Pet schema, focus is on: body (nothing focused)
next Tab stops inside the expanded schema: button: button "Pet" [expanded] (aria-expanded=true) | button: button "[...]" (aria-expanded=false) | button: button "[...]" (aria-expanded=false) | button: button "[...]" (aria-expanded=false) | button: button "[...]" (aria-expanded=false) | button: 'button "Owner {...}"' (aria-expanded=false)
after Enter on Owner, focus is on: button: button "Owner" [expanded] (aria-expanded=true)
```

Enter on the `Pet` schema in the Schemas section expands it and drops focus to the document,
which [issue 10705](https://github.com/swagger-api/swagger-ui/issues/10705) lists.
The server picker is a `combobox` with no name, and four property toggles are each named
`[...]`. No scanner flagged the focus loss. Then read one full operation with VoiceOver or NVDA,
because a recorded name is not proof of what a listener hears.

## Check it worked

The fix is one attribute on the code sample: `<pre class="sample" tabindex="0" role="group"
aria-labelledby="first-request">`. The keyboard record does not show the fix: it is the same
before and after, as "When it goes wrong" explains. The scan does, and comes back clean:

```bash
node audit.mjs records/pa11y-after.json
```

```text output
records/pa11y-after.json: pa11y-ci 5.0.0, pa11y 10.0.0, axe-core 4.13.0
  landing      0 findings,   0 known, 0 new
  operation   34 findings,  34 known, 0 new
  search      20 findings,  20 known, 0 new
  try-it      30 findings,  30 known, 0 new
  allowed with no upstream issue yet: aria-prohibited-attr, aria-label on the div that wraps the copy-path button, owner docs-platform
result: no new findings, pass
```

The tests hold the records to these claims and run the exit status of `audit.mjs` for each:

```bash
node --test audit.test.mjs
```

```text output
1..7
# tests 7
# suites 0
# pass 7
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 148.173639
```

## When it goes wrong

The scan passes and the operation pages are full of failures. It scanned the landing page only,
often because the URL list came from a sitemap of hand-written pages. The record from that run:

```bash
node audit.mjs records/pa11y-landing-only.json
```

```text output
records/pa11y-landing-only.json: pa11y-ci 5.0.0, pa11y 10.0.0, axe-core 4.13.0
  landing      0 findings,   0 known, 0 new
  refused: the run did not scan "operation"
  refused: the run did not scan "search"
  refused: the run did not scan "try-it"
result: cannot trust this run
```

It exits 2, because a list of required pages turns a missing page into a failure.

The keyboard pass reaches the code sample before the fix. Chrome makes a scrolling element a Tab
stop by itself when nothing inside it can take focus,[^2] so the before and after keyboard records here are
identical. Keep `tabindex="0"` for the browsers that do not.

The allowlist swallows a finding that is yours. A pattern such as `#operations-` matches a select
you added to a custom plugin too. Keep each `where` as narrow as the markup the renderer emits.

## When not to do this

Do not count the allowlist as fixed. Each entry is a defect your readers still meet, so review
the list on every renderer upgrade. The audit fails on an entry that matches nothing, but an
entry whose pattern is too broad still matches, and only a person reading the list catches it.

Do not gate a pull request on the manual pass. It takes a person and a screen reader, so run it
on a release and before you change renderer.

Skip the allowlist and the CI job for a one-off audit of a site you are about to replace. A
single scan answers that question, and the list would outlive the site.

Do not let one Lighthouse score stand for the audit. The landing page here scored 1 with a
keyboard finding on it, because the rule that finds it is off in Lighthouse's axe run.

## Related how-tos

- [Choose a renderer for your OpenAPI reference site](/howto/choose-a-reference-docs-renderer)

- [Detect a reference site drifting from its OpenAPI spec](/howto/check-a-reference-site-in-ci)

- [Organize a large OpenAPI reference by tags and tag groups](/howto/organise-a-large-openapi-reference)

- [Run a try-it console without leaking credentials](/howto/run-a-try-it-console-safely)

- [Version your guides alongside your API versions](/howto/version-guides-alongside-api-versions)

## Last verified

Verified 2026-11-30 against Node 22.23.5. Every output block is what the command preceding it
printed in the page's code directory, from records `record.sh` wrote with pa11y-ci 5.0.0,
`@lhci/cli` 0.16.1, `swagger-ui-dist` 5.36.0, and Playwright 1.63.0. `@axe-core/cli` was not
run, and its row is read from its README. No screen reader ran, so the listening half of the
manual pass is described, not recorded.

[^1]: The Swagger UI [issue 10703](https://github.com/swagger-api/swagger-ui/issues/10703) says
the page uses `h1` for the title and `h3` for operations and schemas, so `h2` is skipped. A
callback nested in an operation brings `h2` back, in the order `h1`, `h3`, `h4`, `h2`.

[^2]: Chrome's [announcement](https://developer.chrome.com/blog/keyboard-focusable-scrollers)
says a scrolling element takes keyboard focus by default when nothing inside it can. It
first named Chrome 130 and then moved the change to Chrome 132 for performance. The axe rule
that asks for `tabindex` on the same element is called `scrollable-region-focusable`.