Success Criterion 2.4.3 Focus Order: [Level A]
The intent of this criterion is to ensure that when navigating sequentially through a web page, the order of the content is consistent with the meaning of the content and can be operated by the keyboard. This will incorporate use of up/down/left/right arrow keys as well as the tab key.
Techniques
Creating a logical tab order
By default the tab order is left to right, top down. There are times when this not the logical order of doing things. Suppose the page consists of two vertical sections, the left hand column requiring bank contact details and the right hand column requiring bank account details. It makes more sense to complete the contact details and then tackle the account details rather than hop from column to column.
In the following example, the first column is tabbed through followed by the second.
<fieldset>
<legend>Bank Details</legend>
<table>
<tr>
<th colspan="2" >Contact Details</th><th> </th><th colspan="2" >Account Details</th>
</tr>
<tr>
<td><label for="name1">Name:</label></td>
<td><input id="name1" type="text" tabindex="1" /></td>
<td> </td>
<td><label for="accname">Account Name:</label></td>
<td><input id="accname" type="text" tabindex="4" /></td>
</tr>
<tr>
<td><label for="address1">Address:</label></td>
<td><input id="address1" type="text" tabindex="2" /></td>
<td> </td>
<td><label for="accno">Account Number:</label></td>
<td><input id="accno" type="text" tabindex="5" /></td>
</tr>
<tr>
<td><label for="postcode1">Postcode:</label></td>
<td><input id="postcode1" type="text" tabindex="3" /></td>
<td> </td>
<td><label for="sortcode">Sortcode:</label></td>
<td><input id="sortcode" type="text" tabindex="6" /></td>
</tr>
</table>
</fieldset>
Code order matches visual order
If each section were using floated left divs then the contact details precedes the account details as it does visually and default tabbing will complete the contact details section before moving on to the account details section.
<fieldset style="width:30%;float:left">
<legend>Contact Details</legend>
<label for="name2">Name:</label> <input id="name2" type="text" />
<br />
<label for="address2">Address:</label> <input id="address2" type="text" />
<br />
<label for="postcode2">Postcode:</label> <input id="postcode2" type="text" />
</fieldset>
<fieldset style="width:30%;float:left;">
<legend>Account Details</legend>
<label for="accname2">Account Name:</label> <input id="accname2" type="text" />
<br />
<label for="accno2">Account Number:</label> <input id="accno2" type="text" />
<br />
<label for="sortcode2">Sortcode:</label> <input id="sortcode2" type="text" />
</fieldset>
Insert dynamic content after the trigger element
If new content is to be inserted into the page dynamically (i.e. JavaScript), the new content must immediately follow the element that was activated to trigger the script. The triggering element must be a link or a button, and the script must be called from its onclick event. As the element clicked to trigger the event has focus, this ensures that the new content will be the next candidate for tabbing to, assuming that the new content contains elements which can receive focus.
Reordering page sections using the Document Object Model
A common way to reorder items on a page is to use drag and drop techniques. However these methods are not accessible to keyboard users. A useful keyboard method which can also be used by mouse users is to provide and 'up' and 'down' link/button for each item and clicking that control triggers a script to reorder that item using the DOM. This ensures that the visual presentation continues to match the underlying code.
| Name | |||
|---|---|---|---|
Failures
Using default tab order which is not logical
Taking the first example from the techniques section above, if the tabindex attribute were removed tabbing order would resort to the default which would result tabbing going from column to column thus mixing up contact details with account details which could cause some confusion for a screen reader.
Code order not matching visual order
If the bank example that we've been using used floated left and right divs, the code would be in a different order from the visual presentation with the account details section being coded first. Also if tabing is left to the default, the account details would be navigated through before the contact details.
<fieldset style="width:30%;float:right">
<legend>Account Details</legend>
<label for="accname4">Account Name:</label> <input id="accname4" type="text" />
<br />
<label for="accno4">Account Number:</label> <input id="accno4" type="text" />
<br />
<label for="sortcode4">Sortcode:</label> <input id="sortcode4" type="text" />
</fieldset>
<fieldset style="width:30%;float:left;">
<legend>Contact Details</legend>
<label for="name4">Name:</label> <input id="name4" type="text" />
<br />
<label for="address4">Address:</label> <input id="address4" type="text" />
<br />
<label for="postcode4">Postcode:</label> <input id="postcode4" type="text" />
</fieldset>