Dialog and drawer
A modal <dialog>, either centered or as a drawer along one edge of the viewport.
Live example
Modal dialog
<button type="button" commandfor="confirm-dialog" command="show-modal">Delete project…</button>
<dialog id="confirm-dialog" data-dialog aria-labelledby="confirm-dialog-title">
<header>
<h2 id="confirm-dialog-title">Delete project?</h2>
</header>
<p>This deletes the project and its 12 files for everyone. You cannot undo it.</p>
<form method="dialog">
<footer>
<button type="submit" value="cancel" data-button="secondary" autofocus>Cancel</button>
<button type="submit" value="delete" data-button="danger">Delete project</button>
</footer>
</form>
</dialog>
Drawer (end)
<button type="button" commandfor="filters-drawer" command="show-modal">Filters</button>
<dialog id="filters-drawer" data-dialog="drawer end" closedby="any" aria-labelledby="filters-drawer-title">
<header>
<h2 id="filters-drawer-title">Filters</h2>
<button type="button" commandfor="filters-drawer" command="close" data-button="quiet small">Close</button>
</header>
<form method="dialog" class="stack">
<fieldset>
<legend>Status</legend>
<label><input type="checkbox" name="show-open" checked> Open</label>
<label><input type="checkbox" name="show-closed"> Closed</label>
</fieldset>
<div data-field>
<label for="filters-owner">Owner</label>
<input id="filters-owner" name="owner" type="text" autocomplete="off">
</div>
<footer>
<button type="submit" value="apply">Apply filters</button>
</footer>
</form>
</dialog>
Drawer (start)
<button type="button" commandfor="menu-drawer" command="show-modal">Menu</button>
<dialog id="menu-drawer" data-dialog="drawer start" closedby="any" aria-labelledby="menu-drawer-title">
<header>
<h2 id="menu-drawer-title">Menu</h2>
<button type="button" commandfor="menu-drawer" command="close" data-button="quiet small">Close</button>
</header>
<nav aria-label="Drawer" data-nav>
<ul>
<li><a href="#menu-drawer-title" aria-current="page">Overview</a></li>
<li><a href="#drawer-start-title">Projects</a></li>
<li><a href="#drawer-start-title">Settings</a></li>
</ul>
</nav>
</dialog>
Non-modal dialog
<button type="button" data-show-dialog="note-dialog">Show a note</button>
<dialog id="note-dialog" data-dialog closedby="closerequest" aria-labelledby="note-dialog-title">
<header>
<h2 id="note-dialog-title">Autosave is on</h2>
<button type="button" commandfor="note-dialog" command="close" data-button="quiet small">Close</button>
</header>
<p>Changes are saved as you type.</p>
</dialog>
Attributes
| Attribute or value | Where | Effect |
|---|---|---|
data-dialog | <dialog> | header, body and footer layout and the open transition |
data-dialog="drawer [start | end]" | a drawer at the inline-start or inline-end edge (end is the default) | |
closedby="any | closerequest | none" | native: how the dialog can be dismissed |
Children: an optional <header> (heading and close button) and <footer> (actions, end-aligned); everything else is the body.
Motion
Dialogs fade and lift and drawers slide and fade, with @starting-style and transition-behavior: allow-discrete, entering with --dui-motion-easing-enter and leaving with --dui-motion-easing-exit. Durations are --dui-motion-duration-normal (dialog) and --dui-motion-duration-slow (drawer) to open and one step shorter to close, so --dui-motion-scale retunes them. Under prefers-reduced-motion or data-motion="reduced" the movement is dropped and the fade stays (WCAG 2.3.3); data-motion="none" turns it off. transition-behavior and @starting-style are Baseline in every supported engine, so there is no fallback declaration.
Elevation
Dialogs and drawers use --dui-elevation-dialog and its surface (the highest level). The role's 1px ring draws the edge; the border is transparent, and forced colors mode, which drops box-shadow, paints it in a system color.
Keyboard
| Key | Action |
|---|---|
| Enter / Space | on an opener, opens the dialog and moves focus into it |
| Tab | moves to the next focusable element inside the dialog / Shift+Tab: previous |
| Esc | closes the dialog and returns focus to the opener |
Accessibility
showModal()orcommand="show-modal"makes the page inert, moves focus in and returns it on close.- Name each dialog with
aria-labelledby. Putautofocuson the least destructive action. - Esc and the close buttons always work (WCAG 2.1.2).
closedby="any"adds light dismiss.
Specifications
- HTML
<dialog>element - APG Dialog (Modal) pattern
- MDN
<dialog> - MDN Invoker Commands API
- MDN
@starting-style - MDN
transition-behavior - WCAG Animation from interactions
See also
How other systems do it
For comparison only; these are not the standard this system follows.