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 start but aren’t sure where?

Checkout the Planning and managing web accessibility guideBasics - 图1 provided by World Wide Web Consortium (W3C)Basics - 图2

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:

  1. <ul class="skip-links">
  2. <li>
  3. <a href="#main" ref="skipLink">Skip to main content</a>
  4. </li>
  5. </ul>

To hide the link unless it is focused, you can add the following style:

  1. .skipLink {
  2. white-space: nowrap;
  3. margin: 1em auto;
  4. top: 0;
  5. position: fixed;
  6. left: 50%;
  7. margin-left: -72px;
  8. opacity: 0;
  9. }
  10. .skipLink:focus {
  11. opacity: 1;
  12. background-color: white;
  13. padding: .5em;
  14. border: 1px solid black;
  15. }

Once a user changes route, bring focus back to the skip link. This can be achieved by calling focus to the ref provided above:

  1. <script>
  2. export default {
  3. watch: {
  4. $route() {
  5. this.$refs.skipLink.focus();
  6. }
  7. }
  8. };
  9. </script>

See the Pen Skip to Main by Maria (@mlama007) on CodePen.

Read documentation on skip link to main contentBasics - 图3

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 headingsBasics - 图4

  1. <main role="main" aria-labelledby="main-title">
  2. <h1 id="main-title">Main title</h1>
  3. <section aria-labelledby="section-title">
  4. <h2 id="section-title"> Section Title </h2>
  5. <h3>Section Subtitle</h3>
  6. <!-- Content -->
  7. </section>
  8. <section aria-labelledby="section-title">
  9. <h2 id="section-title"> Section Title </h2>
  10. <h3>Section Subtitle</h3>
  11. <!-- Content -->
  12. <h3>Section Subtitle</h3>
  13. <!-- Content -->
  14. </section>
  15. </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 rolesBasics - 图5 to help you achieve this.

HTMLARIA RoleLandmark Purpose
headerrole=”banner”Prime heading: title of the page
navrole=”navigation”Collection of links suitable for use when navigating the document or related documents
mainrole=”main”The main or central content of the document.
footerrole=”contentinfo”Information about the parent document: footnotes/copyrights/links to privacy statement
asiderole=”complementary”Supports the main content, yet is separate and meaningful on its own content
Not availablerole=”search”This section contains the search functionality for the application
formrole=”form”Collection of form-associated elements
sectionrole=”region”Content that is relevant and that users will likely want to navigate to. Label must be provided for this element

Tip:

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 elementsBasics - 图6.

Read more about landmarksBasics - 图7