Dialogs are modal windows built on the native <dialog> element. They trap focus, darken the backdrop, and support header, body, and footer sections. Opening and closing is handled via data-dialog-open and data-dialog-close attributes.


Tokens

Token Default (Light) Default (Dark) Purpose
Dialog surface
560px Maximum width
0 8px 32px var(--black-alpha-20) 0 8px 40px var(--black-alpha-60) Drop shadow
rgba(0, 0, 0, 0.6) Backdrop overlay

Basic usage

Dialog title

This is the dialog body content. It can contain any HTML — text, forms, images, or other components.

<button class="button" type="button" data-dialog-open="my-dialog">Open dialog</button>

<dialog id="my-dialog" class="dialog">
  <div class="dialog-header">
    <h3 class="dialog-title">Dialog title</h3>
    <button class="dialog-close" type="button" aria-label="Close"><!-- close icon --></button>
  </div>
  <div class="dialog-body">
    <p>Dialog content here.</p>
  </div>
  <div class="dialog-footer">
    <button class="button is-faded" type="button" data-dialog-close>Cancel</button>
    <button class="button" type="button" data-dialog-close>Confirm</button>
  </div>
</dialog>

Confirmation dialog

A destructive action pattern with a danger-styled confirm button.

Delete project?

This action cannot be undone. All files, settings, and history for this project will be permanently deleted.


JavaScript

Include assets/js/dialog.js on any page using dialogs.

<script src="/assets/js/dialog.js"></script>
  • data-dialog-open="dialog-id" on a trigger opens the dialog via showModal()
  • data-dialog-close or inside a dialog closes it
  • Clicking the backdrop also closes the dialog

Keyboard interactions

Key Action
Escape Closes the dialog
Tab Cycles through focusable elements inside the dialog (focus is trapped)
Enter / Space Activates the focused button

Accessibility notes

  • Uses the native <dialog> element — focus trapping is handled by the browser
  • The dialog title should use aria-labelledby pointing to the ID
  • Close buttons must have aria-label="Close"
  • The backdrop is created by the browser's ::backdrop pseudo-element

Do / Don't

Do:

  • Use dialogs for actions that require confirmation or focused input
  • Keep dialog content concise — one task per dialog
  • Always provide a way to dismiss (close button + Escape + backdrop click)

Don't:

  • Don't use dialogs for content that should be inline on the page
  • Don't stack dialogs on top of each other
  • Don't use dialogs for simple alerts — use callouts or toasts instead

Was this page helpful?

We use this feedback to improve our documentation.

Thanks for your feedback