Max Design

Published: | Author: Russ Weakley

Keyboard focus is essential for a wide range of users, especially:

But how do browsers know where to send focus? Are there specific rules they need to follow?

The answer is yes.

Keyboard focus is not guesswork. It is defined across several parts of the HTML and DOM specifications, each describing a different aspect of how focus should behave.

This article highlights six key documents that determine keyboard focus behaviour.

Who should care about these specifications?

Understanding where focus rules live is valuable for anyone who builds or maintains interactive user interfaces, including:

1. Front-end developers

Especially those working with complex, non-native components such as:

2. Accessibility professionals

Knowing the true source of focus behaviour helps you:

3. Design system and component library teams

Design systems fail when focus becomes unpredictable. These teams must ensure:

4. UX designers and interaction specialists

Understanding the native rules leads to simpler, more robust designs. Focus rules shape:

5. QA testers and auditors

Knowing how focus should behave helps testers:

Why should you care?

Together, these specifications explain the foundations of keyboard interactions:

Let’s look at the specs!


1. HTML Standard — “Sequential focus navigation”

Section: 6.6.5 Sequential focus navigation

This section defines how the browser decides which element receives focus when the user presses Tab or Shift+Tab. It is the closest thing to the “focus navigation algorithm” most developers imagine.

It defines:


2. HTML Standard — “The focusing steps”

Section: Focus steps

These are the actual steps a browser runs when setting focus.

It defines:

This is the core “what happens during focus” algorithm.


3. HTML Standard — “Can be focused” steps

Section: Can be focused

This algorithm determines whether an element is allowed to receive focus. It answers the common question: “Why isn’t this element getting focus?”

It checks:


4. HTML Standard — “Tabindex order”

Section: The tabindex attribute

This section defines how tabindex values influence the tab order.

A key detail is that tabindex values greater than 0 create a custom tab order, which must be sorted numerically before any tabindex="0" or native focusable elements. This often leads to unexpected or broken focus patterns on large UIs.

It defines:


5. HTML Standard — “Popover focusing steps”

Section: Popover focus

This algorithm handles the focus behaviour associated with popovers and popover-like UI. Although the Popover API is new, its focus rules affect many common interaction patterns.

It affects:

This matters even if you aren’t using the Popover API directly, because many UI libraries mirror this behaviour.


6. Shadow DOM–specific focus rules

Sections: Shadow tree and Retargeting

The DOM Standard doesn’t define its own “focus algorithm,” but it defines the rules that shape how focus behaves inside custom elements. These rules explain why focus inside custom elements can feel different to focus in the light DOM.

These documents define:


Conclusion

These six documents form an overall “rulebook” that browsers follow when managing keyboard focus.

Understanding these rules is important when diagnosing issues, designing reliable interactions, and building components that work predictably for everyone who relies on the keyboard.