accessibility-guidelines

This document is in beta. Help us by reporting issues via Github or email.

Back to the overview page

Focus order

The order in which interactive elements receive keyboard focus must be natural and predictable.

Actionable items should receive the keyboard focus in an order that makes sense for users, and makes the interface easy to operate.


On this page:


Requirements

Why?

Keyboard users and screen reader users use the ‘Tab’ key to navigate between the focusable (interactive) elements on a page. If that navigation doesn’t happen in a logical way, it’s difficult to understand:

How does this work?

The order in which elements are laid out on screen should match the order in which they’re defined in the Document Object Model (HTML document).

But some (discouraged) CSS and HTML techniques can create a mismatch here. We shouldn’t use those techniques.

See Rob Dodson explain ‘Focus order’ in this short video:


Guidance for Design

A common design mistake

More guidance for design


Guidance for code

Be careful how you order elements in the DOM is it impacts user experience

Example

<div>
  <h3>Shipping Address</h3>
  <label for="n1">Name</label><input type="text" />
  <label for="a1">Address</label><input type="text" />
  ...
</div>
<div>
  <h3>Billing Address</h3>
  <label for="n2">Name</label><input type="text" />
  <label for="a2">Address</label><input type="text" />
  ...
</div>

Failure example

<table>
  <tr>
    <td>Shipping Address</td>
    <td>Billing Address</td>
  </tr>
  <tr>
    <td>
      <label for="n2">Name</label>
      <input type="text" />
    </td>
    <td>
      <label for="n1">Name</label>
      <input type="text" />
    </td>
  </tr>
  <tr>
    <td>
      <label for="a1">Address</label>
      <input type="text" />
    </td>
    <td>
      <label for="a2">Address</label>
      <input type="text" />
    </td>
  </tr>
</table>

Manage keyboard focus when needed to make the interface easy to operate

Do not use positive values with tabindex

Example

<h1 tabindex="-1">I'm the heading for a modal dialog</h1>
...
<div tab-index="0" class="fake_button" aria-role="button">Button Label</div>

Failure example

<div tab-index="3" class="fake_button" aria-role="button">Button Label</div>

Be careful when using CSS Float, Flexbox, Grid and position

Make new content appear in the DOM right after the element that triggers it

How to test whether elements appear in a logical reading order in the DOM

Common mistakes

More guidance for Web


More info

Official wording in the Web Content Accessibility Guidelines

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. (Level A)

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

Sources

Contribute

This document is in beta. Help us by reporting issues via Github or email.