pa11y
Runs automated accessibility tests on your pages via the command line or No...
README
Pa11y
Pa11y is your automated accessibility testing pal. It runs accessibility tests on your pages via the command line or Node.js, so you can automate your testing process.
On the command line:
- ```sh
- pa11y https://example.com
- ```
In JavaScript:
- ```js
- const pa11y = require('pa11y');
- pa11y('https://example.com').then((results) => {
- // Use the results
- });
- ```
Requirements
Pa11y 7 requires [Node.js][node] 18 or 20 to run. An older version of Node.js can be used with a previous major version of Pa11y.
Linux and macOS
To install [Node.js][node] you can use [nvm][nvm]. For example, to install with nvm with [Homebrew][brew], and then install the latest version of Node:
- ```sh
- brew install nvm
- nvm install node
- nvm install-latest-npm
- ```
Alternatively, you can also download pre-built packages from the [Node.js][node] website for your operating system.
Windows
On Windows 10, download a pre-built package from the [Node.js][node] website. Pa11y will be usable via the bundled Node.js application as well as the Windows command prompt.
Command-line interface
Install Pa11y globally with [npm][npm]:
- ```sh
- npm install -g pa11y
- ```
This installs the pa11y command-line tool:
- ```sh
- Usage: pa11y [options] <url>
- Options:
- -V, --version output the version number
- -n, --environment output details about the environment Pa11y will run in
- -s, --standard <name> the accessibility standard to use: WCAG2A, WCAG2AA (default), WCAG2AAA – only used by htmlcs runner
- -r, --reporter <reporter> the reporter to use: cli (default), csv, json
- -e, --runner <runner> the test runners to use: htmlcs (default), axe
- -l, --level <level> the level of issue to fail on (exit with code 2): error, warning, notice
- -T, --threshold <number> permit this number of errors, warnings, or notices, otherwise fail with exit code 2
- -i, --ignore <ignore> types and codes of issues to ignore, a repeatable value or separated by semi-colons
- --include-notices Include notices in the report
- --include-warnings Include warnings in the report
- -R, --root-element <selector> a CSS selector used to limit which part of a page is tested
- -E, --hide-elements <hide> a CSS selector to hide elements from testing, selectors can be comma separated
- -c, --config <path> a JSON or JavaScript config file
- -t, --timeout <ms> the timeout in milliseconds
- -w, --wait <ms> the time to wait before running tests in milliseconds
- -d, --debug output debug messages
- -S, --screen-capture <path> a path to save a screen capture of the page to
- -A, --add-rule <rule> WCAG 2.1 rules to include, a repeatable value or separated by semi-colons – only used by htmlcs runner
- -h, --help output usage information
- ```
Testing with pa11y
Find accessibility issues at a URL:
- ```sh
- pa11y https://example.com
- ```
The default test runner is [HTML_CodeSniffer][htmlcs], but [axe] is also supported. To useaxe:
- ```sh
- pa11y https://example.com --runner axe
- ```
Use both axe and HTML_CodeSniffer in the same run:
- ```sh
- pa11y https://example.com --runner axe --runner htmlcs
- ```
Generate results in CSV format, and output to a file, report.csv:
- ```sh
- pa11y https://example.com > report.csv --reporter csv
- ```
Find accessibility issues in a local HTML file (absolute paths only, not relative):
- ```sh
- pa11y ./path/to/your/file.html
- ```