Skip to content

Accessibility

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 users in a loud environment, deaf users or those who find it hard to hear. 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 provided by World Wide Web Consortium (W3C)

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:

// js
<span ref="backToTop" tabindex="-1" />
<ul class="skip-links">
<li>
<a href="#main" ref="skipLink" class="skip-link">Skip to main content</a>
</li>
</ul>

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

// css
.skip-links {
list-style: none;
}
.skip-link {
white-space: nowrap;
margin: 1em auto;
top: 0;
position: fixed;
left: 50%;
margin-left: -72px;
opacity: 0;
}
.skip-link:focus {
opacity: 1;
background-color: white;
padding: 0.5em;
border: 1px solid black;
}

Once a user changes route, bring focus back to the very beginning of the page, right before the skip link. This can be achieved by calling focus on the backToTop template ref (assuming usage of vue-router):

// vue
<script setup>
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const backToTop = ref()
watch(
() => route.path,
() => {
backToTop.value.focus()
}
)
</script>

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.

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
// template
<main role="main" aria-labelledby="main-title">
<h1 id="main-title">Main title</h1>
<section aria-labelledby="section-title-1">
<h2 id="section-title-1"> Section Title </h2>
<h3>Section Subtitle</h3>
<!-- Content -->
</section>
<section aria-labelledby="section-title-2">
<h2 id="section-title-2"> Section Title </h2>
<h3>Section Subtitle</h3>
<!-- Content -->
<h3>Section Subtitle</h3>
<!-- Content -->
</section>
</main>

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 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=“footer”Information about the parent document: footnotes/copyrights/links to privacy statement
asiderole=“complimentary”TSupports the main content, yet is separated and meaningful on its own content
mainrole=“main”The main or central content of the document.
formrole=“form”Collection of form-associated elements

When creating a form, you can use the following elements: <form>, <label>, <input>, <textarea>, and <button>

Labels are typically placed on top or to the left of the form fields:

// template
<form action="/dataCollectionLocation" method="post" autocomplete="on">
<div v-for="item in formItems" :key="item.id" class="form-item">
<label :for="item.id">{{ item.label }}: </label>
<input
:type="item.type"
:id="item.id"
:name="item.id"
v-model="item.value"
/>
</div>
<button type="submit">Submit</button>
</form>

Notice how you can include autocomplete='on' on the form element and it will apply to all inputs in your form. You can also set different values for autocomplete attribute for each input.

Provide labels to describe the purpose of all form control; linking for and id:

// template
<label for="name">Name: </label>
<input type="text" name="name" id="name" v-model="name" />

If you inspect this element in your Chrome DevTools and open the Accessibility tab inside the Elements tab, you will see how the input gets its name from the label:

Accessibility image

The World Wide Web Consortium (W3C) Web Accessibility Initiative (WAI) develops web accessibility standards for the different components:

Web Content Accessibility Guidelines (WCAG)​

Section titled “Web Content Accessibility Guidelines (WCAG)​”

WCAG 2.1 extends on WCAG 2.0 and allows implementation of new technologies by addressing changes to the web. The W3C encourages use of the most current version of WCAG when developing or updating Web accessibility policies.

WCAG 2.1 Four Main Guiding Principles (abbreviated as POUR):​

Section titled “WCAG 2.1 Four Main Guiding Principles (abbreviated as POUR):​”
  • Perceivable
  • Users must be able to perceive the information being presented
  • Operable
  • Interface forms, controls, and navigation are operable
  • Understandable
    • Information and the operation of user interface must be understandable to all users
  • Robust
    • Users must be able to access the content as technologies advance

Web Accessibility Initiative – Accessible Rich Internet Applications (WAI-ARIA)​

Section titled “Web Accessibility Initiative – Accessible Rich Internet Applications (WAI-ARIA)​”

W3C’s WAI-ARIA provides guidance on how to build dynamic content and advanced user interface controls.