Accessibility Wiki

Closing a dialog must return focus to its opener

Rule dialog-focus-return · Component patterns (best practice) · impact serious · Live only (static → incomplete)

↩ Back to the rules index · WCAG cross-reference

Why it matters

A keyboard or screen-reader user who opens a dialog and closes it expects to land back on the button that opened it. If focus is instead dropped to the page , they are thrown to the top of the page and lose their place. The engine opens each unambiguous dialog trigger, closes it with Escape, and checks where focus landed.

How to fix

When the dialog closes, move focus back to the element that opened it (store the opener on open, call opener.focus() on close). A native

opened with showModal() restores focus automatically.

Example

✕ Fails
<button aria-haspopup="dialog" onclick="openModal()">Open dialog</button>
✓ Passes
<dialog id="d"><button autofocus>Close</button></dialog><button aria-haspopup="dialog" onclick="d.showModal()">Open dialog</button>

WCAG success criteria

2.4.3 Focus Order — Level A

Focus must move in an order that preserves meaning and operability.

Understanding 2.4.3

Standards

This rule contributes to the following standards:

WCAG A EN 301 549

Standard Criteria
EN 301 549 9.2.4.3

References