Modal

Native HTML dialog with size, placement, backdrop, and motion variants

Modal

Modal uses only the native HTML <dialog> element. Both Modal and Dialog share the browser’s dialog behavior with different styling classes.

Open a modal with showModal() or an Invoker Command. The browser owns the top layer, background inertness, keyboard focus containment, Escape dismissal, and focus restoration. CSS controls appearance only.

Basic usage

Use <dialog class="modal"> with a .modal-box child. These examples use native commandfor buttons to open and close the dialog.

Basic Modal

The browser opens and closes this modal through native commands. A form with method="dialog" can also provide closing actions.

Sizes

Apply size modifiers to the dialog; the .modal-box child fills its width.

Modal Sizes

Class Maximum content width
.modal-sm 20rem
Default / .modal-md 32rem
.modal-lg 48rem
.modal-xl 64rem
.modal-full Available viewport width and height

Placement

The default and .modal-middle positions are centered. .modal-top and .modal-bottom align the box to a viewport edge.

Modal Placement

Motion and backdrop

Motion modifiers change the box transition. Backdrop modifiers belong on the dialog and style its native ::backdrop. Reduced-motion preferences remove the transitions.

Modal Motion and Backdrop

Motion classes are .modal-slide-up, .modal-slide-down, and .modal-zoom. Backdrop classes are .modal-backdrop-light, .modal-backdrop-blur, and .modal-no-backdrop.

Responsive and scrollable content

.modal-responsive becomes a bottom-aligned sheet on narrow screens. .modal-scrollable constrains a long body. Other content modifiers are .modal-centered and .modal-no-padding.

Responsive Modal

Native state and dismissal

Use commandfor="dialog-id" command="show-modal" to open and command="close" to dismiss. Applications can call the same native methods when Invoker Commands are unavailable:

const modal = document.querySelector('dialog.modal');
modal.showModal();
modal.close();

A <form method="dialog"> also closes the modal when submitted and sets its native returnValue. Read the close event to handle the result. Use autofocus on the appropriate initial control.

Use showModal() for modal interactions. show() and the static open attribute display a non-modal dialog and do not make the background inert. Visibility follows the native open state; do not toggle CSS classes to open a modal.

Escape closes the modal through the native cancel event. For flows that must prevent dismissal, the application may cancel that event. Backdrop dismissal is optional: set closedby="any" when supported to allow native light dismissal, or keep an explicit close or cancel button. The backdrop is the browser’s ::backdrop pseudo-element.

Accessibility

  • Give each dialog an accessible name with aria-labelledby or aria-label.
  • Give every close button an accessible name.
  • Let showModal() handle focus containment, background inertness, Escape, and focus restoration.
  • Use aria-describedby for a short description when useful, and role="alertdialog" only for urgent confirmation content.

Native modal behavior requires browser support for HTML dialog. Applications may use showModal() and close() directly; do not replace dialog semantics with a regular overlay element.

Migration from legacy overlays

Replace regular overlay elements with <dialog class="modal">, keep .modal-box and the appearance modifiers, and open with showModal() or Invoker Commands. Replace hash links and checkbox labels with buttons. Remove custom backdrop elements and apply backdrop modifiers to the dialog itself. Remove application focus traps and inertness handlers that duplicate native modal behavior.

API reference

Area Classes / API
Structure dialog.modal, .modal-box, .modal-header, .modal-title, .modal-body, .modal-footer, .modal-action, .modal-close
Size .modal-sm, .modal-md, .modal-lg, .modal-xl, .modal-full
Placement .modal-top, .modal-middle, .modal-bottom
Motion .modal-slide-up, .modal-slide-down, .modal-zoom
Backdrop .modal-backdrop-light, .modal-backdrop-blur, .modal-no-backdrop on the dialog
Content .modal-responsive, .modal-scrollable, .modal-centered, .modal-no-padding, .alert-dialog
State Native open attribute, showModal(), close(), Invoker Commands, method="dialog"

Modal consumes DuskMoon surface, content, radius, shadow, scrim, and motion tokens across themes.

  • Dialog — an alternative appearance for the same native HTML dialog contract.
  • Popover — non-modal contextual content.
  • Drawer and Bottom Sheet — edge-attached navigation and tasks.