Accessibility (a11y)

  • It is about designing and building digital products so that, regardless of a person’s disability, they can still interact with the product in a meaningful and equivalent way.
  • Visual
    • Screen reader, magnification
  • Mobility (cannot use mouse)
    • speech input
  • Hearing
    • Captions and transcripts of media
  • Cognitive (Difficult focussing)
    • Screen readers, text highlighting
  • Seizure and vestibular disorders (difficulty with motion)
    • Reduce motion and animations
  • Speech
    • Speech generating device
  • SEO bots
    • crawling friendly
  • ref:

Testing

  • aka Accessibility audit
  • WCAG guidelines
  • Conformance levels: A < AA < AAA
  • POUR principles:
    • Perceivable: information conveyed to multiple senses
    • Operable: The interface cannot require interaction that a user cannot perform.
    • Understandable: Content should be clearly written
    • Robust: focuses on supporting assistive technologies/multiple devices
  • Tools
    • Lighthouse

Internationalization (i18n)

  • Intl namespace provided in browser which has utility functions for language sensitive string comparison, number formatting, and date and time formatting
  • Don’t use images which has text in them since you then need to support multiple images with different languages.
    • Instead, separate the text and the image, and use CSS to overlay the text on the image.
  • If you’re using a web font, make sure it has a range of characters broad enough to cover the languages you’ll be translating into
  • Use two letter ISO language codes
  • i18n validator: https://validator.w3.org/i18n-checker/

Primary language declaration

  • declare the primary language of documents and indicate internal language changes.
  • There can only be one primary language of the page
<!doctype html>
<html lang="fr"> <!-- can also use locale "fr-FR" -->
<head>
...
  • You can also use lang to specify language for any part of html
<p>I felt some <span lang="de">schadenfreude</span>.</p>

Specify Linked Document’s Language

  • We can use hreflang on <a> and <link> to specify linked document language:
  • Used on <a> tag to specify target page’s language
<!-- lang is also used since the text itself is in german -->
<a href="/path/to/german/version" hreflang="de" lang="de">Deutsche Version</a>
  • Used on <link> tag to specify alternate language version page
<head>
	<link href="/path/to/german/version" rel="alternate" hreflang="de">
	...
</head>

Logical Properties

  • Many different languages have different orientation
  • Block flow is the direction in which content blocks are placed.
  • For example, if there are two paragraphs, the block flow is where the second paragraph will go.
  • Inline flow is how text flows in a sentence.
  • English is read left to right (inline axis) and then top to bottom (block axis)
  • Other languages are not the same
  • Hence for a text property:
    • leftright we should use inline startinline end respectively
    • topbottom we should use block startblock end respectively
    • width we should use inline size
    • height we should use block size
  • Example:
    • One really common user interface pattern is a text label with a supporting inline icon.
    • The icon sits to the left of the text with a small gap between the two, provided by margin-right on the icon.
    • We should use margin-inline-end instead
  • flexbox and grid by default use logical properties instead of left, right, top, bottom
  • Logical properties are also applied to sizing, spacing, positioning, borders, units
  • ref:

Localization (l10n)

Color Vision Deficiencies

  • People can have color visions like:
    • Protanopia: missing red
    • Deuteranopia: missing green
    • Tritanopia: missing blue
  • In chrome rendering tab we can emulate different vision deficiencies
  • It’s not a good idea to rely purely on color to differentiate between different elements.
  • For example if you have a chart with legend on colors, consider using pattern, icon, text as well to make it more accessible
  • You can make your links a different color to the surrounding text. But you should also apply some other styling indicator like underlining the links or making them bold.

Contrast

  • If there isn’t enough contrast between the foreground color and background color, text becomes difficult to read.
  • It’s a good idea to always declare color and background-color together in your CSS.
body {  
  color: black;
  background-color: white; 
}
  • Don’t assume that the background color will be the browser default.
  • High Contrast: For Detecting High Contrast OS setting, we can use prefers-contrast media query which has values:
    • no-preference
    • less
    • more
  • Inverted Colors: Check manually if website makes sense if colors are inverted from OS settings
  • Testing tools: tota11y, VisBug

Typography

  • Choose commonly used font instead of custom/handwritten fonts
  • Choose font which has less confusion among pairs:
    • b, d
    • p, q
    • f, t
    • i, j
    • m, w
    • n, u
    • I, l, 1 (India, Lettuce, 1)

Font Size

  • People increase the font size as they age
  • Use relative size for fonts
  • Avoid using units like px. Use relative units like rem or ch instead
  • Someone visiting your website on a desktop computer with their font size bumped up to 400% should get the same layout as someone visiting your site on a small-screen device
  • CSS sizing units

Keyboard Navigation

  • Links styled with the :hover and :focus pseudo-classes will display those styles regardless of whether someone is using a mouse, a trackpad, or a keyboard.
  • Use the :focus-visible pseudo-class to style your links for just keyboard navigation.

Focus Order

  • Test your webpage using tab key on keyboard
  • Focus order in webpage includes naturally focusable HTML elements like links, checkboxes and text inputs
  • Don’t set tabIndex property on HTML elements with value 1 or greater
    • tabIndex=1 or greater defines an explicit tab or keyboard navigation order. (MUST BE AVOIDED). It causes the keyboard navigation to jump first to it.
    • tabindex="0" allows elements besides links and form elements to receive keyboard focus. If you use this then you must provide additional keyboard support for full accessibility.
    • tabindex="-1" value removes interactive elements from the default navigation flow. This can be used on inactive/disabled elements
  • Structure your underlying source code so that the reading/navigation order (via keyboard) is correct.
  • If you have multiple navigation links on the top, it is better to provide skip link as first focus element to help navigation to main quickly
  • Skip link usually have text: “Skip to main content” and can be hidden until Tab is pressed
<header>
  <a href="#content" class="visually-hidden">Skip to main content</a>
  <nav>
    <ul>
      <li><a href="#">Menu item 1</a></li>
      <li><a href="#">Menu item 2</a></li>
    </ul>
  </nav>
</header>
<main id="content">
	....
</main>

Focus indicator

  • Focus should be sufficiently visible with contrast if keyboard navigation is used
a:focus {  
  /* Never make outline: none */
  outline: auto 5px Highlight; /* for non-webkit browsers */  
  outline: auto 5px -webkit-focus-ring-color; /* for webkit browsers */  
}

Title

  • It should be accurate, unique, and descriptive, but also concise.
  • It is also best practice to “front load” the interior page or important content first, since it is read again and again by assistive technologies
<!-- Incorrect -->
<title>The Food Channel | Outrageous Pumpkins | Season 3 </title>
<!-- Correct -->
<title>Season 3 | Outrageous Pumpkins | The Food Channel</title>
  • In SPAs, navigation is usually done at client side, and the title is not automatically updated, so it is better to update the title manually using javascript

Headings

  • Use headings like <h1><h2><h3> … sensibly.
  • Screen readers use these headings to generate an outline of your document which can be navigated with keyboard shortcuts.

Structure

  • Use landmark elements like <main><nav><aside><header>, and <footer> to structure your page’s contents.
  • Screen-reader users can then jump straight to these landmarks.
  • HTML Semantic elements

iframe

  • Use title in iframe
  • Always enable scrolling inside iframe

Images

  • Always use alt attribute to describe image
<img alt="lily" src="http://somewes.png" />
  • If the image is purely presentational, you should still include the alt attribute but you can give it an empty value.
<img alt="" src="texture.png">
  • If the image is complex and needs longer description then you can show the description and link it to image via aria-describedby with id where description is:
<div>
    <img src="Ladybug_Anatomy.svg" alt="Diagram of the anatomy of a ladybug." aria-describedby="description">
    <p id="description">In this course, you will learn more about the anatomy of a ladybug, including the head, antenna, eye, pronotum, elytra, leg, abdomen, and wing.</p>
</div>

Tables

  • Use <caption> tag to describe table
<table>
  <caption>A typical HTML table</caption>  
  <tr>
    <th scope="col">Given Name</th>
    <th scope="col">Family Name</th> 
    <th scope="col">Age</th>
  </tr>
</table>

Links

  • Try to provide descriptive text within links. Avoid using phrases like “click here” or “more.”
<p>Find out more about <a href="offers.html"> our latest offers</a>.</p>

Video and Audio

  • Captions: Include Background sounds for people with disabilities
    • Closed Captions (CC): Can be open/closed by toggle
    • Open Captions (OC): Text burned into the video
  • Subtitles: For people who can hear but may not understand ex. watching foreign film
  • Transcript: Very similar to Captions. meant for people with disabilities.
    • Very detailed, capturing all sound, visual info, essentials words
  • subtitles captions transcripts

Live Area

Forms

  • The WAI Web site hosts a Forms tutorial to make truly accessible forms
  • Associate labels: for must match the id of <input> tag
<!-- example 1 separate label and input -->
<label for="first_name">Your First Name</label>
<input id="first_name" type="text" name="fname"/>
 
<!-- example 2 nesting input inside label with use of span-->
<label for="first_name"><span lang="en">Your First Name"</span>
     <input id="first_name" type="text" name="fname"/>
</label>
  • textarea is similar:
<label for="address">Enter your address:</label>
<br>
<textarea id="address" name="addresstext"></textarea>
  • fieldset performs grouping and legend describes the group
<fieldset>
    <legend>Output format</legend>
    <div>
        <input type="radio" name="format" id="txt" value="txt" checked>
        <label for="txt">Text file</label>
    </div>
    <div>
        <input type="radio" name="format" id="csv" value="csv">
        <label for="csv">CSV file</label>
    </div>
[…]
</fieldset>
  • Use required attribute to notify browser that input is required
  • Appropriate error handling

Consider character encoding

  • Always use the UTF-8 (Unicode) character encoding for content, databases, etc.
  • Always declare the encoding.
  • Also you should save the file in the same encoding as well
<head>
	<meta charset="utf-8"/>
	...
</head>

Character References (Escapes)

  • Use characters rather than escapes (e.g. á á or á) whenever you can.
  • types:
    • Named
    • Number (Decimal prefix: &#and Hex prefix: &#x)
SymbolNameNumber (Decimal)
<&lt&#60
>&gt&#62
&&amp&#38
<space>&nbsp&#160
"&quot&#34

ARIA

  • stands for “Web Accessibility Initiative - Accessible Rich Internet Applications”
  • If you develop UI elements for which there is no semantic HTML element, we need to provide aria attributes
  • Its vocabulary allows you to provide semantic information when there isn’t a suitable HTML element available.
    • Roles: These define what an element is or does.
      • Example: role="navigation", role="search"
    • Properties: Used to give them extra meaning or semantics.
      • Example: aria-required="true" (specifies that a form input needs to be filled in order to be valid)
    • States: Define the current conditions of element. It can change throughout lifecycle of element.
      • Example: aria-disabled="true" (form input is currently disabled)
  • HTML semantic elements work out of the box, Use ARIA if really needed
  • ref: https://developer.mozilla.org/en-US/docs/Learn/Accessibility/WAI-ARIA_basics

Accessibility Tree

  • It is a tree of accessibility objects that assistive technology can query for attributes and properties and perform actions on.
  • HTML DOM tree is converted to AOM (Accessibility Object Model) tree
  • It can be accessed via chrome devtools: https://developer.chrome.com/blog/full-accessibility-tree/