Skip to content

PA11Y for PHPCreate accessibility reports using php.

Getting Started

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.

Requirements

  • PHP 8.3 or newer, as constrained by composer.json (^8.3)
  • Laravel 13, as constrained by illuminate/support (^13.0)
  • Node ^22.13.0 || >=24
  • Chrome or Chromium for Puppeteer to drive
  • The fork jk-oster/pa11y-ci, not upstream pa11y-ci, because the package passes its config as an inline JSON string

Installation & setup

Install the PHP package:

composer require jk-oster/pa11y-php

Install both CLI tools globally:

npm install -g pa11y github:jk-oster/pa11y-ci

The package also ships Composer scripts for the same steps:

composer install:pa11y-globally
composer install:pa11y-ci-globally
composer install:pa11y-linux-requirements

install: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 chrome

Quick start

Audit 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();

Configuration

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.

Setup notes and limitations

  • Chrome or Chromium must be installed. In containers, pass --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.
  • Sitemap URLs are audited as written. The result key is the URL after pa11y normalisation, usually with a trailing slash.
  • Node 22.13 or later, or Node 24 and later. Older Node versions are rejected by 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().

Testing

composer test

The tests call live URLs and run the global pa11y and pa11y-ci binaries. Install the CLI tools before running them.

Documentation