axe-core

repository·develop·Indexed 27 days ago

https://github.com/dequelabs/axe-core

An accessibility testing engine for HTML-based user interfaces that allows developers to automate accessibility audits (WCAG 2.0, 2.1, 2.2) within functional testing workflows. It provides a JavaScript API via axe.run() to identify violations and axe.configure() for runtime customization, including localization and custom rules. The engine balances WCAG spec conformance with actual assistive technology support across various browser and screen reader combinations.

Tokens
29.3K
Snippets
76
Records
156
Agent score
92%

What's inside axe-core

  1. Understand the Axe-core Architecture (Rules and Checks)

    develop

    Axe-core tests for accessibility using a hierarchy of Rules and Checks.

    • Rules: High-level accessibility aspects (e.g., color contrast, button labels). A Rule consists of one or more Checks. A Rule passes if its required Checks pass (based on any, all, or none logic).
    • Checks: The granular tests that perform the actual evaluation. A Check returns true, false, or undefined.

    Rules are defined in JSON files in lib/rules and Checks in lib/checks.

  2. Understand axe-core Best Practice rules

    develop
    In addition to strict WCAG 2 conformance rules, axe-core includes 'Best Practice' rules. These rules identify patterns that significantly improve application usability even if they are not strictly required for WCAG 2 compliance. These rules represent Deque's expert opinion on accessibility best practices.
  3. Best practices for axe-core rule design

    develop

    To ensure high-quality rules and clear error reporting, follow these design principles:

    1. Single none check: Rules should ideally only have one none check to ensure the resulting error message is specific and actionable.
    2. Avoid mixing check types: Do not combine any and none check types within a single rule; instead, break them out into separate rules.
    3. Atomic checks: Each check should test only a single specific case (either one passing technique or one failing test condition).
    4. Simplicity: When describing check logic in a proposal, use short, high-level sentences rather than exhaustive logic.
  4. Understand axe-core issue impact levels

    develop

    axe-core assigns an impact level to each accessibility issue based on the likely effect on users with disabilities. While these levels provide a baseline, users should evaluate each issue within the specific context of their application, as actual impact may be higher or lower.

    Impact levels are categorized into four tiers: Minor, Moderate, Serious, and Critical. For a complete mapping of specific rules to their assigned impacts, refer to the rule-descriptions.md documentation.

  5. Prepare a Pull Request via Rebase

    develop

    To avoid merge messages in the commit log, ensure your branch is up to date with develop by rebasing before submitting a pull request.

    If you have already pushed changes to your branch, use the following commands to rebase against origin/develop:

    git checkout your-branch
    git fetch
    git rebase origin/develop
    git push origin head -f
  6. Set up the axe-core development environment

    develop
    To develop on axe-core, ensure you have Node.js version 24 or higher installed. If using nvm, run nvm use in the repository root. Then, install the necessary npm development dependencies by running npm install in the root folder.
    nvm use
    npm install
  7. Integrate axe-core into web pages and iframes

    develop
    To use the axe JavaScript Accessibility API, you must include the axe.js file in the web page under test. Additionally, axe.js must be included in every iframe that requires testing. Parameters are passed as standard JavaScript function parameters, and results are returned in JSON format.
  8. Perform two-stage accessibility testing with axe.runPartial and axe.finishRun

    develop

    Use axe.runPartial and axe.finishRun to test a page in two stages. This approach is useful when frame communication is restricted (e.g., cross-origin frames) or insecure, as it does not require communication between frames.

    To use this pattern:

    1. Call axe.runPartial(context, options) in the top window and in all nested frames/iframes.
    2. Collect the resulting PartialResult objects into an array.
    3. Pass that array to axe.finishRun(partialResults, options) to generate the final AxeResults report.

    Important Notes:

    • Serialization: axe.runPartial is designed to be serialized, so it will not return element references even if the elementRef option is set.
    • Security: axe.finishRun may access cross-origin information. It should only be called in an environment known to be free of third-party scripts (e.g., a blank page in a browser driver).
    • Origin: Unlike axe.run(), axe.runPartial can run in any frame regardless of origin because it does not require frame communication.
    const partialResults = await Promise.all(runPartialRecursive(context, options));
    const axeResults = await axe.finishRun(partialResults, options);
  9. Implement custom rulesets and reporters for two-stage runs

    develop

    When using axe.finishRun, the execution happens outside the original page context. Consequently, reporter and after methods do not have access to the top-level window or document objects and may lack access to common browser APIs.

    Requirements for Custom Logic:

    • Do not rely on browser APIs or globals.
    • Use the environmentData property (available on the partialResult object of the initiator) to access necessary environment information.
    • Alternatively, collect data within an evaluate method of a check and store it using the .data() method.
  10. Build localized versions of axe-core

    develop

    To create a custom build of axe-core with a specific language, use the --lang flag with the build command. You can also build all localized versions or a specific list of languages.

    • Build a single language: npm run build -- --lang=<langcode> (e.g., npm run build -- --lang=nl)
    • Build multiple specific languages: npm run build -- --lang=nl,ja
    • Build all localized versions: npm run build -- --all-lang

    Localized builds will be named axe.<lang>.js and axe.<lang>.min.js.

    npm run build -- --lang=nl