Focus order

On this page 7

Focus order is the sequence in which keyboard focus moves between interactive elements of an interface, such as links, buttons, form fields and custom controls, when a user presses Tab or Shift+Tab. In accessibility, a correct focus order follows the logical reading and operating sequence of the content, so that people who navigate without a mouse encounter elements in an order that preserves meaning.

The requirement is formalized in WCAG success criterion 2.4.3 Focus Order at Level A, the minimum conformance level. It matters to keyboard users, screen reader users, people using switch devices or voice control, and anyone with motor impairments. Designers influence focus order as much as developers do, because layout, grouping and component choices determine what a sensible sequence looks like.

How browsers determine focus order

By default, a browser builds the focus order from the order of elements in the DOM, the underlying document structure, not from their visual position. Natively focusable elements, such as links with an href, buttons, inputs, selects and textareas, enter the sequence automatically, while non-interactive elements are skipped.

Developers can modify this sequence with the tabindex attribute. The table below shows how its values behave and when each is appropriate.

ValueBehaviorRecommended use
No tabindexNative focusability and DOM orderDefault for standard controls
tabindex=”0″Adds element to the sequence in DOM orderCustom interactive widgets
tabindex=”-1″Focusable by script but skipped by TabDialog headings, error summaries, roving focus
Positive tabindexMoves element ahead of all othersAvoid in almost all cases
Effect of tabindex values on focus order

Positive tabindex values are a well-known anti-pattern. They create a separate ordering that is difficult to maintain, and as soon as new elements are added, the sequence jumps unpredictably across the page.

What a logical focus order looks like

A logical focus order matches the visual reading order for the language of the page: left to right and top to bottom in English, right to left in Arabic or Hebrew. Within a layout, focus should move through a header, then navigation, then main content, then complementary areas and the footer, unless the design has a clear reason to differ.

  • Related controls stay together, so a form completes one group of fields before moving on.
  • Primary actions follow the fields they act on, not precede them.
  • Skip links appear first, allowing users to bypass repeated navigation.
  • Hidden content is not focusable, so collapsed panels and off-screen menus do not trap users in invisible elements.

WCAG does not require focus order to match visual order exactly; it requires that the order preserves meaning and operability. A sequence that differs from the visual layout can still conform if it is logical, but in practice any noticeable mismatch confuses sighted keyboard users.

Focus order in relation to neighboring accessibility concepts

Focus order is often confused with related requirements. The comparison below clarifies how it differs from reading order, focus visibility and keyboard operability.

ConceptQuestion it answersWCAG reference
Focus orderDoes focus move in a meaningful sequence?2.4.3, Level A
Meaningful sequenceIs the reading order exposed correctly to assistive technology?1.3.2, Level A
Keyboard operabilityCan every function be used with a keyboard?2.1.1, Level A
No keyboard trapCan focus always leave a component?2.1.2, Level A
Focus visibleCan users see where focus currently is?2.4.7, Level AA
Focus not obscuredIs the focused element hidden by sticky content?2.4.11, Level AA
Focus order and related concepts

These requirements reinforce each other. A perfect sequence is of little value if the focus indicator is invisible, and a visible indicator does not help if focus jumps erratically between unrelated regions.

Managing focus in dynamic interfaces

Modern interfaces change content without full page loads, so focus must sometimes be moved deliberately by script. When a modal dialog opens, focus moves into it, stays within it while open and returns to the trigger on close. When a single-page application changes route, focus typically moves to the new main heading so screen reader users know the view has changed.

Composite widgets such as tab lists, menus, grids and toolbars use roving tabindex or aria-activedescendant. With this technique, the whole widget occupies a single stop in the Tab sequence, and arrow keys move between items inside it, which keeps the overall order short and predictable.

PatternWhere focus goesReason
Modal dialog opensFirst focusable element or dialog headingContent behind is inert
Modal dialog closesElement that opened itUser keeps their place
Form submitted with errorsError summary or first invalid fieldProblem is announced immediately
Item deleted from a listNext item or the list headingFocus is not lost to the page body
Route change in an applicationNew page headingSignals the change of view
Focus handling for common dynamic patterns

Typical focus order failures and their fixes

Focus order defects usually arise when CSS changes the visual layout without matching changes in the DOM. Techniques such as flexbox order, CSS grid placement and absolute positioning can make the screen look correct while keyboard focus jumps across columns.

  • Reordered layouts: keep source order aligned with visual order instead of rearranging with CSS.
  • Focus lost after an action: when an element is removed, move focus to a sensible neighbor.
  • Off-screen menus still focusable: apply hidden, display: none or the inert attribute.
  • Cookie banners placed at the end of the DOM: place them early or move focus to them when they appear.

The most reliable test is manual: unplug the mouse and tab through the page, noting each stop. Designers can prevent most problems by adding focus order annotations to wireframes and mockups, numbering interactive elements so developers implement the intended sequence.

Stripped to the essentials

Some people move around a website using only the keyboard, pressing the Tab key to jump from one button or field to the next. Focus order is the route that the Tab key follows.

A good route is like a well-planned museum tour: you see the rooms in a sensible order and never get sent back to the entrance by surprise. The key point is that the jumps should follow the way the page reads, so nobody gets lost.

Where it is applied

A public library redesigns its online checkout page for borrowed e-books. The visual design places the summary panel on the right and the payment of late fees on the left, but the developers had used CSS grid placement so that the DOM listed the summary last and the confirmation button first. Keyboard users reached Confirm before they had filled in any field.

During an accessibility audit, a tester using only the keyboard recorded 14 focus stops in a confusing order. The team annotated the intended sequence on the mockup, reordered the markup to match it and removed two positive tabindex values. The retest showed a clean sequence of 11 stops from the skip link to the confirmation button, and the page then met success criterion 2.4.3.