Menu

1 / 2

Keep focus inside the dialog (Web HIG tip #13)

DEV Community: html·FrozonFreak·17 days ago
#UCDmoCYg
#devto2#devto#dev#focus#dialog
Reading 0:00
15s threshold

Open a modal on your site, the cookie settings, a confirm step, or a sign-in box, and press Tab a few times. If the focus ring disappears behind the dark overlay and lands on a link in the page underneath, a keyboard user is now working in a part of the page they can't see.

Web HIG tip #13 (Quick #73 / HIG-A11Y-008): Modals must trap focus inside and restore focus to the trigger on close.

Why it matters

A modal says "deal with this first". Focus has to agree with what the screen shows:

If Tab leaves the dialog, keyboard and switch users end up on controls hidden behind the overlay, and pressing Enter acts on something they can't see

Screen reader users who move past the dialog's content read the page behind it as if the dialog weren't there

If focus isn't moved in when the dialog opens, the user has to hunt for it, or doesn't know it opened at all

If focus isn't put back on close, it usually drops to the top of the page, and the user has to find their place again

The full HIG covers this in §5.3,…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.