|
| 1 | +--- |
| 2 | +title: "HTML Accessibility Checks" |
| 3 | +css: |
| 4 | + - autodark.css |
| 5 | +--- |
| 6 | + |
| 7 | +::: callout-note |
| 8 | +This feature was introduced in Quarto 1.8. |
| 9 | +::: |
| 10 | + |
| 11 | +Quarto includes integrated support for [`axe-core`](https://github.com/dequelabs/axe-core), a broadly-supported, open source, industry standard tool for accessibility checks in HTML documents. |
| 12 | + |
| 13 | +## Accessibility checks with `axe-core` |
| 14 | + |
| 15 | +To enable the simplest form of accessibility checks in Quarto 1.8, add the `axe` YAML metadata configuration to HTML `format`s (`html`, `dashboard`, and `revealjs`): |
| 16 | + |
| 17 | +``` yaml |
| 18 | +format: |
| 19 | + html: |
| 20 | + axe: true |
| 21 | +``` |
| 22 | +
|
| 23 | +In this situation, if your webpage has accessibility violations that `axe-core` can catch, Quarto will produce console messages that are visible by opening your browser's development tools. |
| 24 | + |
| 25 | +### Customization |
| 26 | + |
| 27 | +Quarto supports two additional output formats for the accessibility checks, available through the `output` option. |
| 28 | + |
| 29 | +- `document`: embedded reports |
| 30 | + |
| 31 | + ``` yaml |
| 32 | + format: |
| 33 | + html: |
| 34 | + axe: |
| 35 | + output: document |
| 36 | + ``` |
| 37 | + |
| 38 | + With this option, Quarto will generate a visible report of `axe-core` violations on the webpage itself. This is useful for visual inspection of a page. Note that with this setting, Quarto will always produce a report. |
| 39 | + |
| 40 | + If you wish to use this feature, we recommend adding it to a "debug" [project profile](/docs/projects/profiles.qmd) to reduce the chance you will accidentally publish a website to production with these reports. |
| 41 | + |
| 42 | +- `json`: JSON-formatted console output |
| 43 | + |
| 44 | + ``` yaml |
| 45 | + format: |
| 46 | + html: |
| 47 | + axe: |
| 48 | + output: json |
| 49 | + ``` |
| 50 | + |
| 51 | + This option is useful if you're comfortable with browser automation tools such as [Puppeteer](https://pptr.dev/) and [Playwright](https://playwright.dev/), since it produces output to the console in a format that can be easily consumed. |
| 52 | + |
| 53 | + Specifically, the JSON object produced is the result of running `axe-core`'s `run` method on the webpage. We defer to `axe-core`'s [documentation for full information on that object](https://github.com/dequelabs/axe-core). |
| 54 | + |
| 55 | +- `console` |
| 56 | + |
| 57 | + ``` yaml |
| 58 | + format: |
| 59 | + html: |
| 60 | + axe: |
| 61 | + output: console |
| 62 | + ``` |
| 63 | + |
| 64 | + This option is equivalent to `axe: true`. |
| 65 | + |
| 66 | +## Example: insufficient contrast |
| 67 | + |
| 68 | +As a minimal example of how this works in Quarto, consider this simple document: |
| 69 | + |
| 70 | +::: light-content |
| 71 | + |
| 72 | +``` qmd |
| 73 | +--- |
| 74 | +title: Testing Quarto's accessibility checker |
| 75 | +format: |
| 76 | + html: |
| 77 | + axe: |
| 78 | + output: document |
| 79 | +--- |
| 80 | +
|
| 81 | +This violates contrast rules: [insufficient contrast.]{style="color: #eee"}. |
| 82 | +``` |
| 83 | + |
| 84 | +::: |
| 85 | + |
| 86 | +::: dark-content |
| 87 | + |
| 88 | +``` qmd |
| 89 | +--- |
| 90 | +title: Testing Quarto's accessibility checker |
| 91 | +format: |
| 92 | + html: |
| 93 | + axe: |
| 94 | + output: document |
| 95 | +--- |
| 96 | +
|
| 97 | +This violates contrast rules: [insufficient contrast.]{style="color: #111"}. |
| 98 | +``` |
| 99 | + |
| 100 | +::: |
| 101 | + |
| 102 | + |
| 103 | +This is the produced result visible on the page: |
| 104 | + |
| 105 | +::: {.light-content} |
| 106 | + |
| 107 | +::: |
| 108 | + |
| 109 | +::: {.dark-content} |
| 110 | +{.autodark} |
| 111 | +::: |
| 112 | + |
| 113 | +## Planned work: automated checks before publishing |
| 114 | + |
| 115 | +Currently, this feature requires users to open the webpage in a [local preview](/docs/websites/index.html#website-preview), and it uses a CDN to load the `axe-core` library itself. |
| 116 | + |
| 117 | +In the future, we envision a mode where every page of a website can be checked at the time of `quarto render` or `quarto publish` in order to reduce the amount of required manual intervention. |
0 commit comments