Single pages
Run pa11y against one URL and read errors, warnings, and notices as typed objects.
pa11y-php runs the pa11y and pa11y-ci command line tools from PHP and returns typed result objects. You get the same audits as the CLI, with counts and filters that fit into application code, reports, and tests.
use JkOster\Pa11y\Pa11y;
$result = Pa11y::fromUrl('https://example.com')->run();
$result->getErrorsCount();
$result->getWarningsCount();
$result->getNoticesCount();Pa11y runs one page. Pa11yCi runs a list of URLs or a sitemap and returns Pa11yCiResult with the results grouped by URL. The full method list is in the API reference.
composer.json (^8.3)illuminate/support (^13.0)^22.13.0 || >=24jk-oster/pa11y-ci, not upstream pa11y-ci, because the package passes its config as an inline JSON stringInstall the PHP package:
composer require jk-oster/pa11y-phpInstall both CLI tools globally:
npm install -g pa11y github:jk-oster/pa11y-ciThe package also ships Composer scripts for the same steps:
composer install:pa11y-globally
composer install:pa11y-ci-globally
composer install:pa11y-linux-requirementsinstall:pa11y-linux-requirements installs the shared libraries and Chromium on Debian and Ubuntu with apt-get. Run it with sudo on a server, or install Chrome another way and point Puppeteer at it with PUPPETEER_EXECUTABLE_PATH.
Puppeteer installs a matching Chrome build on a normal npm install. If the browser is missing, run:
npx puppeteer browsers install chromeAudit one page:
use JkOster\Pa11y\Pa11y;
$result = Pa11y::fromUrl('https://example.com')->run();
foreach ($result->getErrors() as $issue) {
echo $issue->getCode().': '.$issue->getMessage().PHP_EOL;
}Audit a list of URLs:
use JkOster\Pa11y\Pa11yCi;
$result = Pa11yCi::fromUrls([
'https://example.com',
'https://example.org',
])->run();
echo $result->getTotalErrorsCount().' errors on '.$result->getUrlsCount().' pages'.PHP_EOL;Audit a sitemap:
use JkOster\Pa11y\Pa11yCi;
$result = Pa11yCi::fromSitemap('https://example.com/sitemap.xml')->run();Both classes accept fluent configuration before run(). Pa11y passes options to the pa11y CLI and uses the pa11y.config.json file in the package root by default:
use JkOster\Pa11y\Pa11y;
$result = Pa11y::fromUrl('https://example.com')
->standard('WCAG2AA')
->timeout(20000)
->ignore('WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail')
->run();Pa11yCi builds one config array, merges it over its defaults, and passes it to pa11y-ci as inline JSON:
use JkOster\Pa11y\Pa11yCi;
$result = Pa11yCi::fromUrls(['https://example.com'])
->viewport(320, 480)
->includeNotices(false)
->concurrency(2)
->run();See the usage guide for every option, the precedence rules, and result accessors.
--no-sandbox through chromeLaunchConfig.args. Pa11yCi does this by default, and the bundled pa11y.config.json does it for Pa11y.Pa11yCi needs the jk-oster/pa11y-ci fork for inline JSON config. Upstream pa11y-ci only accepts a config path.Pa11yCi::fromSitemap() hands the sitemap URL to pa11y-ci. The fork follows sitemap indexes and applies sitemapFind, sitemapReplace, and sitemapExclude.pa11y 10.Pa11y::config() sets --config, but Pa11y still merges its required --config ./pa11y.config.json last. Edit that file or use the other options instead of calling config().composer testThe tests call live URLs and run the global pa11y and pa11y-ci binaries. Install the CLI tools before running them.