Focus management is the practice of programmatically controlling where keyboard
focus is placed as users interact with dynamic content. When content changes,
appears, or disappears on a page, focus must be moved deliberately to ensure
keyboard and screen reader users remain oriented.
[1]
Focus should be moved programmatically in the following situations:
Value
Behaviour
tabindex="0"
Adds element to natural tab order
tabindex="-1"
Removes from tab order but allows programmatic focus via .focus()
tabindex="1+"
Overrides natural tab order — avoid
Use tabindex="-1" on containers like dialog or section elements when you need
to focus them programmatically but do not want them in the tab sequence.
Inside a modal dialog, focus must be trapped — Tab and Shift+Tab should cycle
only through interactive elements within the dialog. Focus must not escape to
the page behind.
[3]
To implement a focus trap:
Every element that receives focus must have a visible focus indicator. Do not
use outline: none in CSS without providing an alternative focus style.
[1]
WCAG 2.2 introduced Success Criterion 2.4.11 (Focus Appearance) which requires
the focus indicator to meet minimum size and contrast requirements.
Losing focus on modal close. If the triggering element no longer exists when
a dialog closes, move focus to a logical nearby element such as a page heading.
Moving focus unnecessarily. Only move focus when content changes in a way
that would disorient users. Avoid moving focus on every keystroke or minor UI
update.
Focusing a non-interactive container. Adding tabindex="-1" to a div and
calling .focus() works, but the element will have no accessible role. Prefer
focusing a heading or the first interactive element inside the region.
Last edited Apr 5, 2026, 7:14 PM · P**** J****