Basics
Web accessibility (also known as a11y) refers to the practice of creating websites that can be used by anyone — be that a person with a disability, a slow connection, outdated or broken hardware or simply someone in an unfavorable environment. For example, adding subtitles to a video would help both your deaf and hard-of-hearing users and your users who are in a loud environment and can't hear their phone. Similarly, making sure your text isn't too low contrast will help both your low-vision users and your users who are trying to use their phone in bright sunlight.
Ready to start but aren’t sure where?
Checkout the Planning and managing web accessibility guide (opens new window) provided by World Wide Web Consortium (W3C) (opens new window)
Skip link
You should add a link at the top of each page that goes directly to the main content area so users can skip content that is repeated on multiple Web pages.
Typically this is done on the top of App.vue
as it will be the first focusable element on all your pages:
<ul class="skip-links"> <li> <a href="#main" ref="skipLink">Skip to main content</a> </li> </ul>
To hide the link unless it is focused, you can add the following style:
.skipLink { white-space: nowrap; margin: 1em auto; top: 0; position: fixed; left: 50%; margin-left: -72px; opacity: 0; } .skipLink:focus { opacity: 1; background-color: white; padding: .5em; border: 1px solid black; }
Once a user changes route, bring focus back to the skip link. This can be achieved by calling focus to the ref
provided below:
<script> export default { watch: { $route() { this.$refs.skipLink.focus(); } } }; </script>See the Pen Skip to Main by Vue (@Vue) on CodePen.
Read documentation on skip link to main content (opens new window)
Structure Your Content
One of the most important pieces of accessibility is making sure that design can support accessible implementation. Design should consider not only color contrast, font selection, text sizing, and language, but also how the content is structured in the application.
Headings
Users can navigate an application through headings. Having descriptive headings for every section of your application makes it easier for users to predict the content of each section. When it comes to headings, there are a couple of recommended accessibility practices:
- Nest headings in their ranking order:
<h1>
-<h6>
- Don’t skip headings within a section
- Use actual heading tags instead of styling text to give the visual appearance of headings
Read more about headings (opens new window)
<main role="main" aria-labelledby="main-title"> <h1 id="main-title">Main title</h1> <section aria-labelledby="section-title"> <h2 id="section-title"> Section Title </h2> <h3>Section Subtitle</h3> <!-- Content --> </section> <section aria-labelledby="section-title"> <h2 id="section-title"> Section Title </h2> <h3>Section Subtitle</h3> <!-- Content --> <h3>Section Subtitle</h3> <!-- Content --> </section> </main>
Landmarks
Landmarks provide programmatic access to sections within an application. Users who rely on assistive technology can navigate to each section of the application and skip over content. You can use ARIA roles (opens new window) to help you achieve this.
HTML | ARIA Role | Landmark Purpose |
---|---|---|
header | role="banner" | Prime heading: title of the page |
nav | role="navigation" | Collection of links suitable for use when navigating the document or related documents |
main | role="main" | The main or central content of the document. |
footer | role="contentinfo" | Information about the parent document: footnotes/copyrights/links to privacy statement |
aside | role="complementary" | Supports the main content, yet is separated and meaningful on its own content |
Not available | role="search" | This section contains the search functionality for the application |
form | role="form" | Collection of form-associated elements |
section | role="region" | Content that is relevant and that users will likely want to navigate to. Label must be provided for this element |
It is recommended to use landmark HTML elements with redundant landmark role attributes in order to maximize compatibility with legacy browsers that don’t support HTML5 semantic elements (opens new window).
© 2013–present Yuxi Evan You
Licensed under the MIT License.
https://v3.vuejs.org/guide/a11y-basics.html