2.1.1 - Keyboard

Make sure every task can be completed using just a keyboard.


Summary

It must be possible for someone using a keyboard to complete all tasks in a website or app. This ensures that people with mobility impairments who do not use a mouse can successfully complete their goals.


Requirements

  • All actionable components can be reached and activated using the keyboard alone.

Why?

  • This ensures that people with mobility or dexterity impairments who do not use a mouse can successfully complete their goals.

  • Lots of people don't rely on a mouse, trackpad or touchscreen to use websites and apps:

    • People who have developed Repetitive Strain Injuries or Arthritis;
    • Screen reader users;
    • Computer power users find keyboard keys and shortcuts to navigate the web.
  • Making a website or app accessible with a keyboard also ensures that it is accessible with other input devices that emulate keyboards, like Switch devices or Sip-and-puff devices.

Official wording in the Web Content Accessibility Guidelines

2.1.1 Keyboard: All functionality of the content is operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement and not just the endpoints. (Level A)

Note 1: This exception relates to the underlying function, not the input technique. For example, if using handwriting to enter text, the input technique (handwriting) requires path-dependent input but the underlying function (text input) does not.

Note 2: This does not forbid and should not discourage providing mouse input or other input methods in addition to keyboard operation.

See the W3C's detailed explanation of this guideline with techniques and examples.


Guidance for Design

This section needs some ❤️
Contribute via Github

See the W3C's detailed explanation of this guideline with techniques and examples.


Guidance for Web

Native HTML interactive elements are keyboard accessible out of the box

  • Use native HTML elements that provided keyboard access automatically;
  • For inactive elements, ensure focus is disabled for controls that support the disabled attribute.

If you don't make use of HTML interactive elements, you need to implement keyboard accessibility yourself

  • If you create an interactive element yourself, make it focusable with the 'Tab' key with tabindex="0". When this element is disabled set tabindex="-1" to remove it from the tab order.

  • Also make sure that you implement responses to keyboard presses that users expect. Look at the keyboard support and focus management guidance in the ARIA Authoring Practices Guide, which covers many common user interface design patterns.

    One of the Rules of ARIA is that:

    "All interactive ARIA controls must be usable with the keyboard."

Hide hidden or off-screen elements for keyboard users and screen reader users too

  • Hidden content (that is off-screen like a side-drawer, or behind other content such as a pop-over, for example), should not be navigable for users of assistive technology as they may think they can interact with this content.

Common mistakes

  • A custom widget has been created, but the necessary keyboard support has not been provided. For example:
    • buttons created using span or div elements rather than button or input elements
    • links created using the span or div, rather than the a element
    • links using a a element but without a URL for their href attribute, or if preventDefault() has been used
  • An <a> element has been used as the basis for a button, but the additional keyboard interaction (activation with the space key) has not been provided;
  • The tabindex attribute has been used on an element with a value of -1 to mistakenly remove it from the tab order.
<!-- standard element that is interactive by default -->
<a href="..."><img src="back.jpg" alt="back" /></a>

Failure example

<!-- clickable image that is not keyboard accessible -->
<img src="back.jpg" alt="back" onclick="myClickEvent();" />

A carousel that supports swiping left and right touch events such as touchstart, touchend, and touchmove can supplement these gestures with keyboard access using buttons, or by watching key presses:

<button onClick="...">Previous</button>
<button onClick="...">Next </button>

Failure example

Listening for touch gestures without providing equivalent control via keyboard:

<script type="text/javascript">
  // perform some action on touch
</script>

...

<div
  ontouchstart="touchStart(event);"
  ontouchmove="touchMove(event);"
  ontouchend="touchEnd(event);"
  ontouchcancel="touchCancel(event);"
>
  <!-- Carousel content -->
</div>

More guidance for Web