Focus management on open and close
When a dialog opens or closes, keyboard and screen reader users can be left behind it, or lost.
The answer
Move focus into a dialog when it opens, and back to the control that opened it when it closes. As strong as the weakest rule behind it: moderate.
-
When a modal dialog opens, move focus into it.
HTML standard behavior and APG (non-binding) agree, and the WCAG 2.4.3 page describes the same behavior in an example, which is informative and sets no floor.
- Applies when
- A modal dialog opens.
- Based on
- Standard or law
- Principle
- Work for everyone
- Common mistake
- Opening a dialog and leaving focus on the page behind.
- StandardStandard: HTML Standard: the dialog elementWHATWG
- GuidanceGuidance: apg-2026-dialog-modal
- Guidance: carbon-2025-modal-danger
-
When an overlay closes, return focus to the control that opened it.
APG and the HTML standard's dialog behavior agree. Primer notes the builder must wire it. No user study of focus return was found.
- Applies when
- An overlay opened from a control closes.
- Based on
- Standard or law
- Principle
- Work for everyone
- Common mistake
- Closing an overlay and leaving focus at the top of the page.
- StandardStandard: HTML Standard: the dialog elementWHATWG
- GuidanceGuidance: apg-2026-dialog-modal
- Guidance: Dialog (GitHub Primer React component)GitHub Primer
The other rules
-
If keyboard focus can get into a component, it must be able to get out by keyboard alone.
WCAG 2.2 success criterion 2.1.2, level A.
- Applies when
- Any component that takes focus.
- Based on
- Standard or law
- Principle
- Work for everyone
- StandardStandard: Understanding SC 2.1.2: No Keyboard TrapW3C WAI
-
Put newly opened content where it makes sense in the focus order, so the next key press reaches it.
WCAG 2.2 success criterion 2.4.3 Focus Order, level A. The criterion page gives dialogs as examples: a non-modal dialog joins the order right after its trigger, and a modal dialog takes focus, keeps the page behind out of reach, and hands focus back to the trigger or the element after it on dismissal.
- Applies when
- Content is added or revealed after an action.
- Based on
- Standard or law
- Principle
- Work for everyone
- StandardStandard: Understanding SC 2.4.3: Focus OrderW3C WAI
-
Don’t let sticky bars or overlays completely hide the focused control.
WCAG 2.2 success criterion 2.4.11 Focus Not Obscured (Minimum), level AA.
- Applies when
- Fixed or overlaid content shares the screen with focusable controls.
- Based on
- Standard or law
- Principle
- Work for everyone
- Common mistake
- A sticky footer that covers the control that has focus.
- StandardStandard: Understanding SC 2.4.11: Focus Not Obscured (Minimum)W3C WAI
-
If that control is gone, move focus to the nearest element that fits what people do next.
APG only; advisory wording.
- Applies when
- The trigger was removed, for example after deleting the item it belonged to.
- Based on
- Practitioner research
- Principle
- Work for everyone
- GuidanceGuidance: apg-2026-dialog-modal
-
When a dialog opens, focus the first field, or the start of long content. Never the destructive button.
The HTML standard uses a marked element, else the first focusable one, else the dialog. APG says it depends: the top for long content, the least destructive control for irreversible steps. Carbon focuses the first input or the primary button.
- Applies when
- A dialog opens.
- Based on
- Convention
- Principle
- Work for everyone
- StandardStandard: HTML Standard: the dialog elementWHATWG
- GuidanceGuidance: apg-2026-dialog-modal
- Guidance: carbon-2025-modal-danger
- Guidance: Dialog (GitHub Primer React component)GitHub Primer
Accessibility
Open questions
- OpenNo user study of focus return or first focus was found; every rule is based on standards and guidance.
- OpenWhere should focus go after content loads or an item is deleted in a list? APG gives one advisory sentence.
Sources
- StandardsStandard: Understanding SC 2.1.2: No Keyboard TrapW3C WAI
- Standard: Understanding SC 2.4.3: Focus OrderW3C WAI
- Standard: Understanding SC 2.4.11: Focus Not Obscured (Minimum)W3C WAI
- Standard: HTML Standard: the dialog elementWHATWG
- GuidanceGuidance: apg-2026-dialog-modal
- Guidance: carbon-2025-modal-danger
- Guidance: Dialog (GitHub Primer React component)GitHub Primer
Related
- Modal dialogsUse a modal only when people must respond before anything else, and only after their own action.Answer: moderate.
- PopoversOpen popovers on click, not hover, and close them with Escape or a click outside.Answer: moderate.
- DrawersPut a panel beside the content when people need both, and send long work to its own page.Answer: moderate.
- Skip linksGive keyboard users a way past repeated blocks: a skip link first in the focus order, and a heading for each section.Answer: moderate.
- Error summariesAfter a failed submit, list every error at the top, each linking to its field, and keep the message at each field too.Answer: moderate.