Web Accessibility for Developers

Agenda

  1. The basics of accessibility
  2. Understanding various disabilities
  3. Semantic HTML
  4. Testing with screen readers
  5. Page structure
  6. Keyboard accessibility
  7. Image alt text
  8. Forms
  9. Links vs Buttons
  10. Dynamic components

And much more!

Intros! đź‘‹

  1. Your name
  2. Favorite Netflix show
  3. What you hope to learn today
Design with an inclusive mindset; create products everyone can use.

What is accessibility?

Mindfulness is key

  • Poor connection speed — Performance
  • Handheld device — Responsive design
  • Person with disability — Accessibility

Disabilities

  • Visual impairments
  • Deafness / hard of hearing
  • Motor disabilities
  • Vestibular issues / seizure disorders
  • Cognitive disabilities

Understanding Disabilities

Visual impairments

A person using a braille reader.
  • Low vision — difficulty seeing things clearly
  • Color blindness — cannot perceive the difference between color
  • Legally blind — only see light, vague shapes, or nothing at all

Challenges and assistive technology

Challenges
People not being able to see the screen or have difficulty discerning color.
Assistive technology
Glasses, text zoom software, screen reader, braille reader.

Deafness / hard of hearing

Two people sitting on a couch signing.
  • Deaf — very little or no functional hearing
  • Hard of Hearing — mild-to-moderate hearing

Challenges and assistive technology

Challenges
People not being able to hear video or audio content.
Assistive technology
Hearing aid, captions/audio descriptions, transcripts.

Motor disabilities

A wheelchair user riding a pool at a skate park wearing a helmet.
  • Paraplegia or quadriplegia — paralysis of the limbs
  • Cerebral palsy — decreased muscle control
  • Parkinson's disease — uncontrollable tremors

Challenges and assistive technology

Challenges
Being accurate with interactions, using a mouse, interacting with small UI elements.
Assistive technology
Keyboard, voice dictation software, wand mouth stick, switch device

Vestibular issues / seizure disorders

A young woman holds her head in pain.
  • Vestibular disorder — feelings of dizziness or Vertigo
  • Seizures — strobing, flickering, or flashing effects

Challenges and assistive technology

Challenges
Navigating a web with an increasing amount of animations, no warning of flashing content
Assistive technology
Using "reader mode" to remove animations, "Reduce motion" operating system feature

Cognitive disabilities

A young child looks off into the distance. A teacher stands at a blackboard behind them, looking for their attention.

Clinical diagnoses:

  • Autism
  • Down Syndrome
  • Dementia/Alzheimer's

Less severe:

  • Attention deficit disorder (ADD)
  • Dyslexia (difficulty reading)
  • Learning disabilities

Challenges and assistive technology

Challenges
Reading content, understanding design patterns, completing timed tasks, general focus
Assistive technology
Using "reader mode" to remove distractions, Kurzweil software

Temporary disabilities

A person's arm slung in a temporary cast.
  • A broken arm or finger
  • Reading text on your phone while outside
  • Loud, busy environment
  • Having Lasik eye surgery
  • Traveling to a new country
  • Holding a baby in one arm and your phone in the other!
Make accessibility considerations for all disabilities to provide an inclusive user experience.

The four principles of accessibility

W3C 👉 WAI 👉 WCAG

A screenshot of the WCAG homepage.

P.O.U.R.

  1. Perceivable
  2. Operable
  3. Understandable
  4. Robust
Perceivable & Operable & Understandable & Robust t-shirt.

Perceivable

Interface components must be presentable to users in ways they can comprehend.

A line graph with various patterns to denote each data point.
  • Short text equivalents for images
  • Description of data represented on charts
  • Brief descriptions of non-text content
  • labels for controls and interface components

Operable

User interface components and navigation must be operable or usable.

A person typing on a keyboard.
  • Functionality available by mouse is also available by keyboard
  • No keyboard traps
  • Web browsers and tooling provides keyboard support

Understandable

Information and the operation of user interface must be understandable or easily comprehensible.

A Japanese street sign.
  • Identify the primary language of a page
  • Providing definitions for uncommon words
  • Use clear and simple language

Robust

Content must be created in a way which can be interpreted reliably by a wide variety of user agents.

A table with various mobile phones and tablets.
  • Markup can be reliably interpreted
  • Provide a name, role, and value

WCAG Success Criteria

Level A
Provides a baseline to meet basic usability needs of most people
Level AA
Includes usability which meets the needs of most people with disabilities
Level AAA
Success criteria to meet the needs of all people and beyond
If any of these principles are not met, users with disabilities will not be able to use the web.

Keyboard

Focus indicator

Animated GIF showcasing the visual focus indicator as someone Tabs through a website.
If you can't see the cursor on the page, you've got an accessibility issue

2.4.7 Focus Visible

"Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible."

Custom focus indicator

            
              *:focus {
                outline: solid 3px red;
              }
            
          
  • Ensure high contrast ratio
  • Make it consistent

Detect keyboard/mouse usage

Focus order

Focus order demo on CodePen

2.4.3: Focus Order

"If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability."

Ensure the visual order of content matches the HTML order.

Focus management

Animated GIF of a modal window opening on a webpage.
The tabindex attribute

tabindex="-1"

  • Allows non-focusable elements to programmatically receive focus via JavaScript
  • Does not add the element to the natural focus order

tabindex="0"

  • Allows non-focusable elements to receive focus
  • Adds the element to the natural focus order

tabindex="1" or higher

  • Send focus to this element first, then focus returns to the next element
  • Considered an anti-pattern and should be avoided
Refrain from adding tabindex="0" everywhere!

Exercise!

  1. Load up the HTML pages of our demo site in your browser.
  2. Try navigating with just the Tab key.
  3. Fix any issues by adjusting the demo-site/css/styles.css file.

Semantic HTML

Semantic HTML is the foundation of an accessible experience.
What is this thing and what does it do?
Semantics include…
  • Accessible name
  • Element role
  • Current state

The accessible name/label/text equivalent

Screen reader focus on a link. A speech bubble reads, 'Contact us'.

The element role

Screen reader focus on a link. A speech bubble reads, 'Contact us, link'.

The current state

Screen reader focus on a checkbox. A speech bubble reads, 'Apples, unchecked, checkbox'.

1.3.1 Info and Relationships

"Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text."

Using semantic HTML is setting up your users for success.

Testing with screen readers

The piece of content which gets announced is the currently focused item.

Common screen reader commands

Starting up

Screen reader Start up Shut down
VoiceOver
  • Cmd + F5
  • TouchBar: Cmd + Pwr (x3)
  • Cmd + F5
  • TouchBar: Cmd + Pwr (x3)
NVDA
  • Ctrl + Alt + N
  • Windows Run dialog: nvda
  • Desktop shortcut
  • Windows Run dialog: nvda -q
  • Taskbar menu

Pause announcements

Homer Simpson's finger pointing at the 'Ctrl' key.

Tabbing around

  • Tab to move forward
  • Shift + Tab to move backward

Screen reader virtual cursor

Screen reader Keys
VoiceOver Ctrl + Opt then Left arrow or Right arrow
NVDA Up arrow or Down arrow

Screen reader + browser combinations

Operating system Browser Screen reader
Windows Internet Explorer JAWS
Windows Firefox NVDA
Windows Firefox JAWS
macOS Safari VoiceOver
iOS Safari VoiceOver
Android Chrome TalkBack

Exercise!

  1. Load up the homepage of our demo site.
  2. Set your system volume to low — just enough so you can hear it.
  3. Start up your screen reader, then shut it off.
  4. Start the screen reader, hit Ctrl to pause.
  5. Try pressing Tab around — how do things sound?
  6. Try your screen reader virtual cursor!

Page title

The page title is the first bit of information that is announced by a screen reader.

How to write title text

Homepage
                <title>outdoorsy</title>
              
Contact page
                <title>Contact | outdoorsy</title>
              
A blog post
                <title>Choose the Right Gear | outdoorsy</title>
              

Updating the state

Form with invalid data
                <title>Error | Contact | outdoorsy</title>
              
Multi-step form
                <title>Payment information (Step 3 of 4) | Shop | outdoorsy</title>
              

2.4.2 Page Titled

"Web pages have titles that describe topic or purpose."

Exercise!

  1. Load up the HTML pages of our demo site in your editor and browser.
  2. Set an appropriate page title.
  3. Bonus! Try starting up a screen reader and refresh the page to hear the title content.

Page structure

People who depend on assistive technology often navigate by headings first.

Logical heading order is key

            
              <h1>Primary heading</h1>
              <!-- … -->

              <h2>Sub-section</h2>
              <!-- … -->

              <h3>Sub-sub-section</h3>
              <!-- … -->

              <h2>Sub-section</h2>
              <!-- … -->
            
          

Examples

Landmark elements

Landmark HTML role Purpose
Header banner Typically the first landmark element in the DOM, containing the main logo, primary navigation, and sometimes a search form.
Footer contentinfo Typically the last element in the DOM, containing links and copyright information.
Aside complimentary Contains content relative to the article or the site in general.
Nav navigation Used to denote navigation areas.
Main main The main content area of the page, typically found as a sibling to the header and footer.
Section — A generic element used for sectioning off content such as portions of a page or article—not to be confused with the div which as no semantic meaning.

2.4.6 Headings and Labels

"Headings and labels describe topic or purpose."

Exercise!

  1. Load up the HTML pages of our demo site in your editor and browser.
  2. Adjust the markup to include Landmark elements such as header, main, footer, aside, etc.
  3. Hint! The applied CSS classes help to decide where a Landmark might be placed.

Image alt text

Who benefits from alt text?

Image on a web page with text bubble, 'Creative writing objects on a table; pens, pencils, a sketch book, and a cup of coffee. Image'

Benefits of alt text include SEO, and sighted users when the image fails to load.

However, screen reader users benefit most; allows participation in consuming non-text content.

Images missing the alt attribute

  • Invalid HTML markup
  • The src attribute value is announced by screen readers

When to include alt text

  • If the image contains text, the alt value should be an exact match
  • If the image doesn’t add any value, the alt attribute value should be left empty
  • If the image adds content or value, add descriptive alt text

How to write alt text

  • Be accurate and descriptive
  • Don't overwhelm with too much information
"A pair of low-top shoes are placed on top of a dark-brown table in front of a white brick wall. The shoes are mostly dark blue with a white midsole, brown laces, a black back tab, and white lining."
"Dark blue, low-top shoes with white midsole, brown lace, black back tab, and white lining."

1.1.1 Non-text Content

"All non-text content that is presented to the user has a text alternative that serves the equivalent purpose."

Exercise!

  1. In your browser and editor, load: demo-site/blog-post.html.
  2. Pick a photo and try writing some alt text describing the image.
  3. Bonus! Use your screen reader virtual cursor to listen to your alt text.

Links vs Buttons

Link and button expectations

Element Is announced as Is activated by Results in Shifts focus?
a "link" Enter Loading a new page, downloading a file, or jumping to a section on the same page. Yes
button "button" Enter or Space Submitting a form or executing an on-screen action (eg., sorting table columns.) No

Control design

Control design and accessibility

An underlined link with the text, 'Link'. A button with the text, 'Button'.
  • Consistent control design allows people to identify and use with confidence
  • Voice dictation software accuracy
  • Color alone may not be enough to perceive the control

Hover, focus, and active state

Hover state

An animated GIF highlighting mouse hover styles; from red to dark red.
            
              a:hover {
                color: FireBrick;
              }
            
          

Focus state

An animated GIF highlighting keyboard focus styles.
            
              a:hover, a:focus  {
                color: FireBrick;
              }
            
          

Active state

An animated GIF highlighting mouse activation styles; dark red to black.
            
              a:active {
                color: Black;
              }
            
          

Notes on the href attribute

The missing href

Don't do this:

            
              <a onclick="doSomething()">Do something</a>
            
          

Do this instead:

            
              <a href="#doSomething" onclick="doSomething()">Do something</a>
            
          

Including a unique href value

Screen reader with multiple speech bubbles of, 'link visited'.

Including a unique href value

Screen reader with speech bubbles of, 'Apples, link', 'Oranges, link'.

2.4.4 Link Purpose

"The purpose of each link can be determined from the link text alone or from the link text together with its programmatically determined link context."

Skip links

The skip link

Animated GIF showcasing a 'Skip to content' link moving focus to the content body.

Skip link requirements

            
              <a href="#main" class="visuallyhidden focusable">Skip to content</a>
            
          
  • Implement as an a element with href
  • Match the href with the id of the container
  • Add .visuallyhidden class
  • Add .focusable class
  • Set as first item in the HTML document

Skip to where?

            
              <a href="#main" class="visuallyhidden focusable">Skip to content</a>
              <!-- … -->
              <main id="main" tabindex="-1">
                <!-- … -->
              </main>
            
          

2.4.1 Bypass Blocks

"A mechanism is available to bypass blocks of content that are repeated on multiple Web pages."

Exercise!

  1. In your browser and editor, load: demo-site/index.html.
  2. Add a skip link to the top of the document.
  3. Add the code for the container to receive focus.

Color contrast

Contrast threshold

Object Ratio
Text and images of text 4.5:1
Large text (greater than 18pt) 3.0:1
Non-text (borders, icons) 3.0:1

Contrast tools

Don't rely on color alone

Screenshot of input field in an error state; red border, light red background, red error text with icon below.
Screenshot of input field in an error state which is difficult to notice; grey border, light grey background, grey error text with icon below.
  • An icon along side error text
  • An underline for links embedded within body text
  • Textures or patterns to differentiate sections of a graph or chart

1.4.3 Contrast (Minimum)

"The visual presentation of text and images of text has a contrast ratio of at least 4.5:1."

Exercise!

  1. Load up the HTML pages of our demo site in your browser.
  2. Right click an element on the page which you suspect may have poor color contrast
  3. Click Inspect
  4. In the Styles tab, find the color property and click the color swatch
  5. Review the color contrast ratio value
  6. Use the color picker to move the cursor below the white line in order to select an accessible color

Forms

Labels

Placeholders

  • đź‘Ž Unable to convey the purpose of the input by screen readers
  • đź‘Ž Placeholder text is removed from view when typing
  • đź‘Ž May look like text has been entered

Give the Placeholder demo a try.

Floating labels

  • đź‘Ť "Floats" labels up above the input when typing
  • đź‘Ť Saves screen real estate
  • đź‘Ť label associated with its input
  • đź‘Ž Small text size
  • đź‘Ž Potential for poor implementation

Give the floating label demo a try.

Always-visible labels

  • đź‘Ť label is consistent, predictable
  • đź‘Ť No cognitive load to remember the input purpose
  • đź‘Ť Screen reader support
  • đź‘Ť Full text size

Try out the always-visible label demo form.

3.3.2 Labels or Instructions

"Labels or instructions are provided when content requires user input."

Error messaging

  • Error text
  • Input styles
  • Error list

Error text

Screenshot of input field in error state. Arrows point out features of error state which bring in attention.

Connecting error text to its input

Screenshot of input field in an error state; red border, light red background, red error text with icon below.

No connection

            
              <label for="fname">First name</label>
              <input type="text"
                id="fname"
                name="fname">
              <span id="error-fname" class="error">First name is required</span>
            
          

Using aria-describedby

            
              <label for="fname">First name</label>
              <input type="text"
                id="fname"
                name="fname"
                aria-invalid="true"
                aria-describedby="error-fname">
              <span id="error-fname" class="error">First name is required</span>
            
          

Error list

Screenshot of error list. Arrows point out features of error list which bring in attention.

3.3.1 Error Identification

"If an input error is automatically detected, the item that is in error is identified and the error is described to the user in text."

Exercise!

  1. In your browser, load: demo-site/blog-post.html and submit the Comment form.
  2. In your editor of choice, load: demo-site/js/form-validation.js.
  3. Add the JavaScript code to connect each input with its related error message.
  4. Bonus! Test with a screen reader to make sure things are connected!

Proximity/text zoom

The straw test

  1. Take one hand and making a fist
  2. Open your fist just enough to let a "straw" through
  3. Hold your fist up to one of your eyes

The straw test "test" part 1

The straw test "test" part 2

1.3.3 Sensory Characteristics

"Instructions provided for understanding and operating content do not rely solely on sensory characteristics of components such as shape, size, visual location, orientation, or sound."

Screenshot of a bank website form. Primary input is at the top of a modal window, call to action buttons are at the bottom.

Responsive design

Avoid 2D scrolling

iPhones with a website loaded. One features a site with both vertical and horizontal scroll bars. The other features the same site but with only a vertical scroll bar.

The viewport meta tag

            
              <meta name="viewport" content="width=device-width, initial-scale=1">
            
          

1.4.10 Reflow

"Content can be presented without loss of information or functionality, and without requiring scrolling in two dimensions."

Touch targets

Touch target size

Touch target example

2.5.5 Target Size

"The size of the target for pointer inputs is at least 44 by 44 CSS pixels."

Whitespace

Offscreen content

Repeated link content

            
              <a href="article/how-to-make-pasta-sauce.html">
                Read more
              </a>
            
          

Providing context without disrupting design

Visually hidden text

            
              <a href="article/how-to-make-pasta-sauce.html">
                Read more
                <span class="visuallyhidden">about How to Make Pasta Sauce</span>
              </a>
            
          

The aria-label approach

            
              <a href="article/how-to-make-pasta-sauce.html"
                aria-label="Read more about How to Make Pasta Sauce">
                Read more
              </a>
            
          

2.4.4 Link Purpose

"The purpose of each link can be determined from the link text alone or from the link text together with its programmatically determined link context, except where the purpose of the link would be ambiguous to users in general."

A few more examples…

A table of buttons

Don't do this:
                
                  <button>Remove</button>
                
              
Do this:
                
                  <button
                    aria-label="Remove {item title}">
                    Remove
                  </button>
                
              

Star ratings

Don't do this:
                
                  <i class="icon icon-star star-4"></i>
                
              
Do this:
                
                  <span class="icon icon-star star-4">
                    <span class="visuallyhidden">4 out of 5</span>
                  </span>
                
              

Offscreen navigation

An animated GIF showcasing offscreen menu being activated and sliding into view.

Completely hiding content

  • CSS display: none (difficult to animate)
  • CSS visibility: hidden (easier to animate)
  • HTML hidden attribute
                    
                      <span hidden>Hidden content</span>
                    
                  
If visually hidden, hide from keyboard and assisitve technology, too.

2.4.3: Focus Order

"If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability."

Animation

What actually makes up a "poor" animation

  • Size of movement — Keep animations small and purposeful
  • Direction and speed – Allow the user to scroll at their own pace.
  • Distance — Refrain from animating long lengths of content

Animation and accessibility

A young woman holds her head in pain.
  • Someone with a cognitive impairment may get easily distracted or frustrated
  • Someone with Vestibular issues may experience vertigo or feel nauseated

Animation example

The prefers-reduced-motion media query

Setting the OS

  1. macOS Settings
  2. Accessibility
  3. Display
  4. Activate the Reduce motion checkbox
Screenshot of macOS Accessibility settings.

Coding a "no animation" state

            
              a {
                color: Crimson;
                transition: color .25s;
              }

              a:focus, a:hover {
                color: FireBrick;
              }

              @media (prefers-reduced-motion) {
                a {
                  transition: none;
                }
              }
            
          

Browser/OS Support

Can I Use – prefers-reduced-motion

2.3.3 Animation from Interactions

"Motion animation triggered by interaction can be disabled, unless the animation is essential to the functionality or the information being conveyed."

Exercise!

  1. In your browser, load: demo-site/blog-post.html and
    • Mouse-over the "Leave a Comment"
    • Click the "Newsletter" link
  2. In your editor of choice, load: demo-site/css/styles.css.
  3. Add the prefers-reduced-motion media query to disable the fade-in animations.

ARIA

How does ARIA accomplish this?

Attribute Purpose Example
role Used to add or alter the base semantic meaning of an element.
                    
                      <div role="button"></div>
                    
                  
aria-label Adds an accessible name to an element.
                    
                      <div role="button"
                        aria-label="Fake button"></div>
                    
                  
aria-disabled Announces the element as in a "disabled" state.
                    
                      <div role="button"
                        aria-label="Fake button"
                        aria-disabled="true"></div>
                    
                  

What ARIA does not do

  • Does not make elements keyboard focusable
  • Does not automatically provide keyboard support

Custom components

Checkbox in HTML

  1. A label element
  2. The input element
  3. A clearly defined state

Checkbox in HTML

            
              <label for="apple-checkbox">
                <input type="checkbox"
                  id="apple-checkbox"
                  name="apple">
                Apple
              </label>
            
          

Checkbox built with ARIA

  1. An accessible name
  2. Its role conveyed
  3. A clearly defined state

Checkbox built with ARIA

            
              <div class="checkbox__wrapper">
                <div class="checkbox__checkbox"
                  role="checkbox"
                  tabindex="0"
                  aria-checked="false"
                  aria-labelledby="apple-checkbox"></div>
                <div class="checkbox__label"
                  id="apple-checkbox">Apple</div>
              </div>
            
          

Non-standard components

Screenshot of a tree-view component.
Screenshot of a tabs component.

Live region components

Screen reader speech bubble announcing, 'Success!'
Refer to the WAI-ARIA 1.1 spec document for more information.

Dynamic components

W3C WAI-ARIA Authoring Practices

Modal window

Animated GIF of a modal window being activated and appearing into view.

Keyboard interaction

Key Expected interaction
Tab
  • Moves focus to the next focusable element inside the modal window.
  • If keyboard focus is on the last focusable element inside the modal, the next Tab keypress moves focus to the first focusable element inside the modal.
Shift + Tab
  • Moves focus to the previous focusable element inside the modal window.
  • If focus is on the first focusable element inside the modal, the next Shift + Tab keypress moves focus to the last focusable element inside the modal.
Escape Dismisses the modal window.

Focus management

  1. Upon activation, shift focus from the control to the modal window
  2. Trap keyboard focus within the modal window
  3. When dismissed, return focus to the control

ARIA roles, states, and properties

Element Attribute Usage
Launcher button aria-haspopup="modal" Informs the user of a modal context upon interaction
Modal container div role="dialog" Identifies the current container and context as a modal window
Modal container div aria-labelledby="IDREF" Helps to describe the purpose of the modal window by referencing the h2 heading element — if no heading is available, use aria-label instead
Modal container div aria-modal="true" Informs assistive technologies that the content underneath the current dialog are not available for interaction

Keyboard trap?

The inert attribute

Definition
When a node is inert, the user agent must act as if the node was absent for the purposes of targeting user interaction events, may ignore the node for the purposes of text search, and may prevent the user from selecting text in that node.
Polyfill
github.com/WICG/inert

Using inert

            
              <header inert>
                <!-- … -->
              </header>

              <main inert>
                <!-- … -->
              </main>

              <footer inert>
                <!-- … -->
              </footer>

              <div class="modal" …>
                <!-- … -->
              </div>
            
          

Exercise!

  1. In your browser, load: demo-site/popup.html
  2. In your editor of choice, load: demo-site/js/modal-window.js
  3. Add the JavaScript code to make the "Sign up for our newsletter" modal accessible!
  4. Bonus! There are other issues to fix — can you find them?
"Don't think of accessibility as a chore that's too difficult to implement, but rather a coding challenge."
– @vavroom

Thank you!

Animated GIF of Harry Potter saying, 'Great work everyone. Well, well done.' Children clapping.

Find me @svinkle — DMs are always open! 🚀