Accessible modal dialogs (focus trap + Escape)

A short, practical UI accessibility note for games and web UIs. No tracking.

Try the micro-demo: modal-demo.html

It compares a modal dialog where focus can escape into background controls (BEFORE) with a focus-trapped modal that supports Escape and restores focus (AFTER).

What goes wrong in many modals

A modal dialog is supposed to be a temporary “mode” where the user must finish a decision (or dismiss it) before interacting with the rest of the UI.

Common failure mode: the modal looks like it blocks the background, but keyboard focus can still move to background links/buttons when the user presses Tab.

Why it matters

A safe pattern (minimal version)

The goal isn’t extra ceremony — it’s to make “open modal” a reliable mode switch for everyone.