Course contentsShow
← Web Development
Lesson 1179 of 2,98221. Accessible ComponentsFree lesson

Focus Management in Tab Interfaces

Managing focus when switching tabs and ensuring focus moves to the active tab or panel content.

Focus Management in Tab Interfaces

You'll learn how to properly move focus when users switch between tabs so keyboard and screen reader users always know where they are in the interface.

Why Focus Management Matters in Tabs

When a user activates a new tab (whether by clicking or pressing arrow keys), focus needs to move intentionally. Without proper focus management, keyboard users might lose their place, and screen reader users won't hear what content just became visible.

Think of it like changing channels on TV: when you press the channel button, you expect the screen to immediately show the new channel. Similarly, when activating a tab, users expect their focus to immediately reflect that change.

Where Should Focus Go?

You have two main strategies:

1. Focus Stays on the Tab Button

After switching tabs, focus remains on the newly activated tab button itself. This works well when users might quickly navigate through multiple tabs using arrow keys.

2. Focus Moves to the Panel

After switching tabs, focus moves into the newly revealed panel content (usually to the panel container or its first interactive element). This works well when users typically work within one tab's content before moving to another.

Most tab implementations use strategy #1 because it supports rapid tab browsing with arrow keys without losing your place in the tab list.

The Key Moment

Focus management happens immediately when the tab activates—whether triggered by click, Enter/Space on the tab button, or arrow key navigation. Your code must explicitly call .focus() on the appropriate element after updating aria-selected and showing the new panel.

Key Takeaway: Always explicitly manage focus when switching tabs—typically keeping focus on the newly activated tab button itself—so keyboard and screen reader users maintain context and control.