# Focus Management

Focus management deliberately controls where keyboard focus moves, remains, and returns as an interface changes.

- Type: practice
- Domain: Experience & interface
- Level: Advanced
- Last reviewed: 2026-09-21
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/focus-management/>)

## What it means

Focus is the active point of keyboard interaction. Good management relies on a logical DOM order by default and moves focus programmatically only when dynamic changes would otherwise leave users lost—for example, opening a modal, adding an error summary, or removing the focused item.

## Why it matters

Predictable focus lets keyboard and screen-reader users understand where they are and continue a task efficiently. Poor focus handling can place users behind overlays, reset them to the document start, hide the active control, or announce changed content without a usable next action.

## When to use it

Plan focus behavior for dialogs, menus, route changes, validation, inserted content, deletion, composite widgets, and any interaction that changes context. Specify initial focus, containment if needed, exit behavior, and the return target.

## How it works

1. Preserve semantic DOM order and let native browser behavior handle ordinary navigation.
2. Define the trigger, initial focus target, internal navigation, and return target for dynamic components.
3. Move focus only when it supports the user’s next task or communicates a context change.
4. Keep the focused element visible and distinguish focus from selection.
5. Restore focus to a logical surviving control when content closes or is removed.
6. Test forward and reverse navigation, zoomed layouts, errors, and assistive technologies.

## A practical example

When a user opens a confirmation dialog, focus moves to its heading or safest actionable control, Tab stays within the modal interaction, Escape closes it when appropriate, and focus returns to the button that opened it. If that trigger was deleted, focus moves to a logical nearby control.

## Where it breaks

Programmatic focus can be disruptive when used to compensate for weak structure or to steer users aggressively. Screen readers have multiple navigation modes, and visual focus styling has separate requirements; focus movement should be tested rather than inferred from code.

## Common mistakes

- Moving focus on every content update.
- Opening a modal while leaving focus behind it.
- Returning focus to an element that no longer exists.
- Confusing selected, active, hovered, and focused states.
- Using aria-activedescendant without implementing visual and keyboard behavior.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/focus-management/#visualization-focus-management>)

## Sources

1. [Developing a Keyboard Interface](<https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/>) — W3C Web Accessibility Initiative · Technical guidance
2. [Understanding Success Criterion 2.4.3: Focus Order](<https://www.w3.org/WAI/WCAG22/Understanding/focus-order>) — W3C Web Accessibility Initiative · Standards guidance
3. [Understanding Success Criterion 2.4.13: Focus Appearance](<https://www.w3.org/WAI/WCAG22/Understanding/focus-appearance>) — W3C Web Accessibility Initiative · Standards guidance

## Related topics

- [Keyboard Accessibility](<https://wiki.soroush.uk/topic/keyboard-accessibility/>)
- [Screen Reader Design](<https://wiki.soroush.uk/topic/screen-reader-design/>)
- [Component Library](<https://wiki.soroush.uk/topic/component-library/>)
