Hub: index · watch · videos

Dialogs (modals) — note

If you open a modal and don’t manage focus, keyboard + screen reader users can get lost “behind the curtain.”

Live demo: Open the dialogs (modals) micro-demo

What goes wrong

Small, reliable pattern

Minimal markup

<button id="openDialog">Edit profile</button>

<div
  role="dialog"
  aria-modal="true"
  aria-labelledby="dlgTitle"
  aria-describedby="dlgDesc"
  hidden
>
  <h2 id="dlgTitle">Edit profile</h2>
  <p id="dlgDesc">Update your display name.</p>
  <label>Display name<input /></label>
  <button type="button" id="closeDialog">Close</button>
</div>

Keyboard expectations

Notes