Component

Dialog

Published on

Description anchor

The dialog component creates a modal overlay using the native <dialog> element with command/commandfor attributes. No JavaScript is required. Dialogs trap focus and provide built-in keyboard dismissal with Escape.

Example anchor

Open in new tab (opens in new tab)
View HTML markup
  <button type="button" command="show-modal" commandfor="dialog-cmd-id">Open dialog</button>
<dialog closedby="any" id="dialog-cmd-id" aria-labelledby="dialog-cmd-heading">
  <form method="dialog" novalidate="">
    <header>
      <h1 id="dialog-cmd-heading">Heading</h1>
    </header>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <footer>Dialog footer<button type="button" command="close" commandfor="dialog-cmd-id" autofocus="">close</button></footer>
  </form>
</dialog>

Accessibility anchor

  • Use native <dialog> with showModal(). It provides built-in focus trapping and the inert attribute for background content.
  • The trigger button should use aria-haspopup="dialog" and aria-expanded to communicate state.
  • Focus placement on open depends on dialog type: short messages focus the close button, longer content focuses the dialog or heading, action-required dialogs focus the least destructive option, and brief forms focus the first input.
  • Always return focus to the triggering element when the dialog closes.
  • Use aria-labelledby pointing to the dialog heading for the accessible name.

References anchor

Variables anchor

none for dialog