|
| 1 | +# Accessibility |
| 2 | + |
| 3 | +Creating and publishing content that does not exclude disabled users is a complex and iterative task. |
| 4 | + |
| 5 | +While there is no one-size-fits-all solution to maintaining accessible content, |
| 6 | +the PyData Sphinx Theme and this documentation site use some techniques to avoid common content shortcomings. |
| 7 | + |
| 8 | +:::{note} |
| 9 | +Issues and pull requests to identify or fix accessibility issues on this theme or site are heartily welcomed! |
| 10 | +::: |
| 11 | + |
| 12 | +## What We've Done |
| 13 | + |
| 14 | +### Metadata |
| 15 | + |
| 16 | +Several of our documentation pages contain metadata (i.e., `.. meta::` directives |
| 17 | +in reStructuredText) giving summaries of the page contents. If you notice a |
| 18 | +page that lacks metadata, please open a pull request to add it! |
| 19 | + |
| 20 | +### Colors |
| 21 | + |
| 22 | +- Our default code highlighting styles are `a11y-high-contrast-light` and |
| 23 | + `a11y-high-contrast-dark` from https://github.com/Quansight-Labs/accessible-pygments. |
| 24 | + These styles are designed to meet WCAG 2 AA or AAA contrast requirements. |
| 25 | + If you don't like the look of our default code highlighting styles, there are several more |
| 26 | + to choose from at https://github.com/Quansight-Labs/accessible-pygments. |
| 27 | +- We recently revisited the PyData Sphinx theme color palette to ensure that |
| 28 | + the colors we use meet WCAG 2 AA or AAA contrast requirements. |
| 29 | +- We also re-defined our `primary` and `secondary` colors to be more accessible and distinct from semantic colors used |
| 30 | + to denote success, warning, info, and danger contexts or information. |
| 31 | +- We simplified the color palette and removed some colors that were problematic in meeting WCAG 2 AA or AAA contrast requirements |
| 32 | + and for certain types of colorblindness. |
| 33 | +- We have improved how we assign text colors to interactive elements such as buttons and dropdowns to ensure that they meet |
| 34 | + WCAG 2 AA or AAA contrast requirements. |
| 35 | + |
| 36 | +## What You Can Do |
| 37 | + |
| 38 | +### Site configuration |
| 39 | + |
| 40 | +The following sections include recommendations for settings in the `conf.py` file that can positively impact the |
| 41 | +accessibility of content generated by this theme and Sphinx in general. |
| 42 | + |
| 43 | +### Natural Language |
| 44 | + |
| 45 | +If not using a more robust [internationalization approach](https://www.sphinx-doc.org/en/master/usage/advanced/intl.html), |
| 46 | +specifying at least the baseline natural language will help assistive technology |
| 47 | +identify if the content is in a language the reader understands. |
| 48 | + |
| 49 | +:::{hint} |
| 50 | +In your `conf.py` file, [specifying the language your docs are written in](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language) will propagate to the top-level `HTML` tag. |
| 51 | + |
| 52 | +```python |
| 53 | + language = "en" |
| 54 | +``` |
| 55 | + |
| 56 | +::: |
| 57 | + |
| 58 | +### Add a Site Map |
| 59 | + |
| 60 | +Site maps, usually served from a file called `sitemap.xml` are a broadly-employed |
| 61 | +approach to telling programs like search engines and assistive technologies where |
| 62 | +different content appears on a website. |
| 63 | + |
| 64 | +If using a service like [ReadTheDocs](https://readthedocs.com), these files |
| 65 | +will be created for you _automatically_, but for some other approaches below, |
| 66 | +it's handy to generate a `sitemap.xml` locally or in CI with a tool like |
| 67 | +[sphinx-sitemap](https://pypi.org/project/sphinx-sitemap/). |
| 68 | + |
| 69 | +:::{hint} |
| 70 | + |
| 71 | +For a simple site (no extra languages or versions), ensure `sphinx-sitemap` |
| 72 | +is installed in your documentation environment, and modify your `conf.py`: |
| 73 | + |
| 74 | +```python |
| 75 | + extensions += ["sphinx_sitemap"] |
| 76 | + |
| 77 | + html_baseurl = os.environ.get("SPHINX_HTML_BASE_URL", "http://127.0.0.1:8000/") |
| 78 | + sitemap_locales = [None] |
| 79 | + sitemap_url_scheme = "{link}" |
| 80 | +``` |
| 81 | + |
| 82 | +::: |
| 83 | + |
| 84 | +### Logo best practices |
| 85 | + |
| 86 | +If you use both light and dark themes, it's best to provide a logo that works well in both or to provide an alternative for the dark theme. |
| 87 | +If you have a logo, you can add alt-text to it by adding the following to your |
| 88 | +`conf.py`: |
| 89 | + |
| 90 | +```python |
| 91 | + "logo": { |
| 92 | + "text": "PyData Theme", |
| 93 | + "image_dark": "_static/logo-dark.svg", |
| 94 | + "alt_text": "PyData Theme home", |
| 95 | + }, |
| 96 | +``` |
| 97 | + |
| 98 | +Note the use of "home" in the alt text to indicate that the logo is also a link to the home page. |
| 99 | + |
| 100 | +### In the Browser |
| 101 | + |
| 102 | +Several in-browser tools exist for interactively debugging the accessibility |
| 103 | +of a single page at a time and can be useful during the content development cycle. |
| 104 | + |
| 105 | +### Built-in tools |
| 106 | + |
| 107 | +Most major browsers, including [Firefox](https://developer.mozilla.org/en-US/docs/Tools/Accessibility_inspector) |
| 108 | +and [Chrome](https://developers.google.com/web/tools/chrome-devtools/accessibility/reference), |
| 109 | +have accessibility tools built-in as part of their web developer tools. |
| 110 | +These tools can help to quickly identify accessibility issues and often include links to standards. |
| 111 | + |
| 112 | +#### tota11y |
| 113 | + |
| 114 | +[tota11y](https://khan.github.io/tota11y/#Installation) is an open source |
| 115 | +"bookmarklet" which modifies the currently-loaded page in place and highlights |
| 116 | +several accessibility issues. |
| 117 | + |
| 118 | +#### WAVE |
| 119 | + |
| 120 | +[WAVE](https://wave.webaim.org/extension/) is a proprietary (but _gratis_) |
| 121 | +browser extension which can highlight multiple issues. |
| 122 | + |
| 123 | +:::{warning} |
| 124 | +Note that automated testing and extensions such as the ones mentioned above will at best catch 30-40% of accessibility issues. |
| 125 | +They are not a replacement for manual testing and having a perfect score on any of these tools does not mean that |
| 126 | +the site can be used by disabled users but instead signals that it follows some accessibility best practices. |
| 127 | +::: |
| 128 | + |
| 129 | +### In Continuous Integration |
| 130 | + |
| 131 | +Several automated tools are available for assessing _glaring_ accessibility |
| 132 | +issues across some pages at once, usually with many configurable options. |
| 133 | + |
| 134 | +#### Lighthouse |
| 135 | + |
| 136 | +[Lighthouse](https://developers.google.com/web/tools/lighthouse) provides an automated assessment of basic accessibility issues in addition to search engine |
| 137 | +automation, page performance, and other best practices. |
| 138 | + |
| 139 | +:::{hint} |
| 140 | +Specifically, [foo-software/lighthouse-check-action](https://github.com/foo-software/lighthouse-check-action) |
| 141 | +is run on selected pages from the generated documentation site. |
| 142 | +::: |
0 commit comments