Sub topic 5
Setting reading order and focus order
This chapter assumes you know how headings and landmarks are sketched on a wireframe (previous chapter) and that you have a basic grasp of HTML and CSS. It covers how to define the order in which content is read and the order in which keyboard focus moves. It also covers the common ways the two drift apart from the visual layout.
Three orders, one page
A page has three orders that users experience, and they are not always the same.
- Visual order is the order a sighted person scans the layout. It follows position, size, contrast and whitespace.
- Reading order is the order assistive technology presents content. Screen readers follow the order of elements in the DOM (the document structure the browser builds from HTML), not their position on screen.
- Focus order is the order in which interactive elements receive keyboard focus when a user presses Tab. It also follows the DOM by default, and it only includes interactive elements.
Two WCAG 2.2 success criteria apply:
- 1.3.2 Meaningful Sequence (Level A): when the order of content affects its meaning, a correct reading order must be programmatically determinable.
- 2.4.3 Focus Order (Level A): focus must move in an order that preserves meaning and operability.
A related criterion, 2.4.11 Focus Not Obscured (Minimum, Level AA), requires that a focused element is not entirely hidden by other content, such as a sticky header. This matters when you place fixed elements in the wireframe.
A wireframe is the cheapest place to settle these orders. At this stage the order is a numbering exercise. After development it is a refactoring of markup and CSS.
Why the orders drift apart
CSS can change what the eye sees without changing the DOM. The usual causes are:
- CSS Grid and Flexbox features such as
order,row-reverseandgrid-areaplacement. - Absolute or fixed positioning that moves an element far from its place in the source.
- Multi-column layouts and card grids where visual rows do not match source order.
- Modals, drawers and menus that are appended at the end of the DOM but appear on top of the page.
- Visual design that puts a call to action beside a heading while the markup puts it at the end of the section.
When this happens, a keyboard user's focus jumps around the screen unpredictably, and a screen reader user hears content in a sequence that may not make sense.
Numbering the order on a wireframe
You can specify both orders directly on the wireframe with a small annotation layer.
- Lay out the regions first: header, navigation, main, complementary content, footer.
- Number regions in the order a screen reader should meet them. A common sequence is skip link, header, navigation, main, complementary, footer.
- Within each region, number the content from most to least important, following the heading outline.
- Mark every interactive element with a second numbering (for example, in a different color or in circles) for focus order.
- Draw arrows only where the order is not obvious from left-to-right, top-to-bottom flow.
In left-to-right languages the default scan is left to right, then top to bottom. In right-to-left languages such as Arabic or Hebrew, the layout mirrors, and so should the numbering. The DOM order stays the same, and the layout direction flips.
A worked example: product card grid
Suppose a card has an image, a title that links to the product, a price and an "Add to basket" button. A common design pattern wraps the whole card in a link. Another pattern puts the button before the title in the source because it is positioned at the bottom with CSS.
A better specification:
- Reading order inside the card: title (as a heading), price, then button.
- Focus order inside the card: title link, then button. The image is decorative, so it takes no focus.
- Focus order across cards: card 1 title, card 1 button, card 2 title, card 2 button. Do not make users tab through all titles first and then all buttons.
<ul class="cards">
<li class="card">
<h3><a href="/p/kettle">Glass kettle</a></h3>
<p>$39.00</p>
<button type="button">Add Glass kettle to basket</button>
</li>
<li class="card">
<h3><a href="/p/toaster">Steel toaster</a></h3>
<p>$54.00</p>
<button type="button">Add Steel toaster to basket</button>
</li>
</ul>The source order here already matches the intended reading and focus order, so no extra attributes are needed. The button text names the product so that a list of buttons read out of context is still distinguishable. This prepares the ground for the later chapter on link and button text.
Rules of thumb for sequences
- Put the main content early in the DOM. Place the skip link first, then repeated blocks such as header and navigation, then
main. A skip link is a link that jumps keyboard users past repeated navigation to the main content (WCAG 2.4.1 Bypass Blocks). - Keep the order of related items together. A label, its field, its hint and its error message should be adjacent in both orders.
- Follow task flow in forms. Fields appear in the order a person completes them. Group related fields with a
fieldsetandlegend. - Place a heading before the content it introduces, including inside cards, dialogs and sidebars.
- Place dynamic content after its trigger. If a button opens a panel, the panel should follow the button in the DOM so that the next Tab press enters it.
- Do not skip non-interactive content in reading order just because it cannot take focus. Text, images with meaning and status messages belong in the reading sequence.
Reordering with CSS: where it breaks
CSS reordering is the most common source of mismatch. Consider this layout, in which the visual design wants the "Buy now" panel on the left and the description on the right, while the source puts the description first.
<div class="product">
<section class="description">
<h2>Details</h2>
<p>Borosilicate glass, 1.7 litre.</p>
<a href="/specs">Full specifications</a>
</section>
<section class="purchase">
<h2>Buy</h2>
<button type="button">Add to basket</button>
</section>
</div>.product {
display: flex;
}
/* Visual only: moves the purchase panel to the left. */
.purchase {
order: -1;
}On screen the purchase panel appears first. A keyboard user, however, tabs first to "Full specifications" in the description and only then to the button on the left. Focus appears to jump backward across the screen. The CSS Flexbox and Grid specifications state that order changes only the visual presentation, and WCAG warns against relying on it when the sequence matters.
Prefer one of these fixes, in this order:
- Change the DOM so the purchase section comes first, and drop the
orderrule. - Change the wireframe so the visual order matches the natural source order.
- Keep the reorder only for items that are purely presentational and contain no interactive content.
Focus order is more than the Tab key
The wireframe should also say where focus goes when the page changes without a full reload.
| Event | Where focus should go | Why |
|---|---|---|
| Dialog opens | Into the dialog, usually the heading or first control | Keeps focus from staying behind the overlay |
| Dialog closes | Back to the element that opened it | Returns the user to their place |
| Inline error on submit | To an error summary or the first invalid field | Lets the user find and fix problems |
| Content deleted from a list | To the next item, or the list heading if empty | Prevents focus from falling to the top of the page |
| Single-page route change | To the new page heading or main region | Announces that the view changed |
| Accordion expands | Stays on the toggle button | The user decides whether to move into the panel |
The "focus lost" case deserves attention. If a focused element is removed from the DOM, the browser moves focus to the body, and keyboard users must start from the top. Specify the destination on the wireframe for each such interaction.
Using tabindex carefully
You rarely need tabindex if the markup is native and ordered well. Know the three values:
tabindex="0"places a non-native element in the natural focus order. Use it only if the element has a role and keyboard handling.tabindex="-1"makes an element focusable by script but not by Tab. It suits a heading or a dialog container that you move focus to.- A positive value, such as
tabindex="3", forces an element ahead of the natural order. Avoid it. It creates a parallel order that is hard to maintain and breaks as soon as content is added.
A short script shows the usual pattern for moving focus to a new heading after a view change:
function showView(titleId) {
const heading = document.getElementById(titleId);
heading.setAttribute("tabindex", "-1");
heading.focus();
}
showView("order-history-title");The tabindex="-1" attribute lets script focus a heading, which is not interactive by default. Screen readers then announce the heading, which tells the user where they are.
Checking the order early
Before visual design starts, you can test the intended order on a low-fidelity wireframe:
- Read the numbering aloud as a screen reader would, ignoring layout. Does the page still make sense as a list?
- Trace the focus numbers with a finger. Does the path zigzag or backtrack?
- For each dynamic interaction, answer the question "where does focus go next?"
- After the first coded prototype, press Tab through the page and watch the focus indicator. Then compare the result with the annotations.
Common errors
- Numbering only the visual flow and assuming the DOM will match.
- Using
order,row-reverseor absolute positioning without checking focus. - Placing a modal's markup at the end of the page without managing focus into and out of it.
- Letting sticky headers cover the focused element.
- Using positive
tabindexvalues to fix an order problem that should be fixed in the source. - Forgetting to specify focus after deleting, adding or filtering content.
Exercise
A wireframe shows a two-column checkout. The order summary sits in the right column visually, but the designer wants it to appear first for screen reader users. A developer proposes moving the summary to the left in the DOM and using CSS order: 2 to keep it visually on the right. The summary contains an "Edit basket" link. What problem can this cause for keyboard users, and what would you specify instead?
Show answer
Keyboard focus follows the DOM, so Tab would reach "Edit basket" in the summary before the form fields on the left, while the eye sees the form first. Focus would appear to jump from the right to the left. Specify one consistent order instead. Either place the summary in the DOM where it should be read and keep the visual layout matching, or change the wireframe so the summary appears in the same sequence visually. Annotate both reading order and focus order, and verify by tabbing through the prototype.
Exercise
A user deletes the item that currently has keyboard focus in a list of saved addresses. Where should the wireframe annotation send focus, and why?
Show answer
Send focus to the next address in the list, or to the previous one if the deleted item was last. If the list is now empty, send it to the list heading or an "Add address" button. Otherwise the focused element is removed, focus falls back to the body, and the keyboard user must tab from the top of the page.