Mental model

Managing Focus

Guiding users through an interface predictably and logically, especially for those using keyboards or assistive technologies.

Discover

A user is filling out a form on your website using only their keyboard. After filling in their email, they press the 'Tab' key. What should happen next for the best experience?

What's the logical next step?

Let's explore why this sequence matters so much.

Understand

Understand

Managing focus means controlling which part of a screen is active, ensuring it moves in a predictable order as a user navigates. The correct next step in the form is for the focus to move to the 'Password' field, because it follows the visual and logical sequence. This is critical for anyone using a keyboard or screen reader, as it acts like a spotlight showing them exactly where they are on the page. For example, when a modal dialog opens, good focus management automatically moves the spotlight into that dialog so you can interact with it immediately.

Try this: Navigate a favorite website using only your Tab key to see if the focus moves in a logical order.

Full explanation

Full explanation

Focus management is the process of ensuring a clear, logical path through a digital interface for users who do not use a mouse. The 'focus' is the active element that receives keyboard input, typically highlighted with a visible outline.

This process is primarily governed by the page's code structure (the Document Object Model or DOM). By default, pressing the Tab key moves focus to the next interactive element in the code. Good design ensures this code order matches the visual layout, creating a predictable path.

Handling dynamic content requires careful focus management. When a user adds a product to a cart, their focus should not be moved to the 'Product Added' notification that appears. Instead, the focus should remain on the 'Add to Cart' button or a logical next step, while the notification is announced to screen readers using an ARIA live region (e.g., role="status"). This prevents disrupting the user's flow.

A critical scenario involves 'focus trapping' within modal dialogs. When a modal opens, focus must be moved inside it and kept there. Tabbing should cycle through the modal's elements and not escape to the page behind it until the user explicitly closes the modal. Critically, once the modal is closed, focus must be returned to the element that originally opened it, such as the 'Settings' button.

Research

Research

Effective focus management is a foundational component of web accessibility, directly impacting task completion for people relying on assistive technologies. Failures in focus visibility and order are among the most severe barriers to digital inclusion. The process involves structuring the DOM logically, using JavaScript to programmatically shift focus, and styling a highly visible focus indicator.

  • The W3C's Web Content Accessibility Guidelines (WCAG) provide explicit success criteria for a logical focus order (2.4.3) [1], a visible focus indicator (2.4.7) [5], and the prevention of keyboard traps (2.1.2) [6], which is especially relevant for modals. (2018)
  • Nielsen Norman Group reports that keyboard accessibility problems, including illogical tab orders and invisible focus indicators, are severe usability issues that can render a site completely unusable for individuals with motor disabilities [2]. (2022)
  • For dynamic applications, developers use JavaScript's focus() method to manage context. This is often paired with the tabindex attribute. Best practice is to avoid positive values (tabindex="1" or higher), as they disrupt the natural document order. Instead, use tabindex="0" to add an element to the default tab sequence and tabindex="-1" to make an element focusable only via script, not by tabbing [3]. (2023)

Limitations

Limitations

While a logical source order is the most robust foundation, it can be challenging to maintain in complex, single-page applications where content is constantly changing. Over-managing focus can also be detrimental; for instance, aggressively moving a user's focus to a notification without their explicit action can be disorienting and interrupt their workflow. The best implementation is context-dependent and often requires user testing with people who rely on keyboard navigation to find the right balance between helpful guidance and unwanted interruption.

Try it

Synthesize

Choose a pattern from the guide, then pick an action to try with it.

Which pattern stands out?

What will you try?

Choose a pattern above to select an action.

Sources

Sources

Try it

Check your understanding

A user clicks a button that opens a settings menu in a pop-up window (a modal). Where should the keyboard focus immediately go?

Show the guide's explanation

Answer: Go to the first interactive element inside the pop-up.

This is a key principle of managing focus with modals. Moving focus into the modal allows keyboard and screen reader users to immediately interact with its content without having to navigate the underlying page.

You are designing a website and notice the default tab order jumps from the main navigation to the footer, skipping the main content. What is the most likely cause?

Show the guide's explanation

Answer: The source code (DOM) places the footer HTML before the main content HTML.

By default, the keyboard navigation or 'focus order' follows the sequence of elements in the HTML code (the DOM). To fix this, the code structure should be changed to match the visual layout.

What is the primary goal of establishing a logical focus order?

Show the guide's explanation

Answer: To ensure the experience is predictable and efficient for keyboard-only users.

A logical focus order directly supports users who navigate without a mouse, making the interface usable and preventing them from getting lost or frustrated.

Keep exploring

Find another idea for the decision in front of you.

The complete Reframo library is free to read. Explore another guide whenever you are ready.