Component
Dialog
A modal dialog using the native dialog element - confirmation, forms, detail views. ::backdrop scrim, @starting-style entry/exit, header/body/footer.
On this page
The .pl-c-dialog is a modal dialog using the native <dialog> element. It
uses top-layer rendering, modal focus trapping, and native Esc-to-close. The
::backdrop pseudo-element provides the page scrim.
Semantic HTML
<!-- Declarative trigger (zero JS in modern browsers) -->
<button class="pl-c-button" commandfor="confirm" command="show-modal">
Delete account
</button>
<!-- closedby="any" enables native backdrop click-to-dismiss -->
<dialog class="pl-c-dialog" id="confirm" closedby="any">
<header class="pl-c-dialog__header">
<h2 class="pl-c-dialog__title">Delete account?</h2>
<button
class="pl-c-dialog__close"
type="button"
aria-label="Close"
commandfor="confirm"
command="close"
>
✕
</button>
</header>
<div class="pl-c-dialog__body">
<p>This action cannot be undone.</p>
</div>
<footer class="pl-c-dialog__footer">
<button
class="pl-c-button"
data-variant="ghost"
commandfor="confirm"
command="close"
>
Cancel
</button>
<button
class="pl-c-button"
data-variant="danger"
commandfor="confirm"
command="close"
>
Delete
</button>
</footer>
</dialog>
Triggering and light dismiss
- Declarative Invoker Commands (Chrome 135+): Use
commandfor="dialog-id"withcommand="show-modal"on the opening button, andcommand="close"on close buttons. No JavaScript required. - Declarative Light Dismiss (Chrome 134+): Add
closedby="any"to<dialog>so clicking the backdrop scrim automatically closes the modal, matchingpopover="auto". - Application JavaScript fallback: In older browsers, wire triggers to
el.showModal()and close buttons toel.close(). PressingEscalways works natively.
Class contract
| Selector | Role |
|---|---|
.pl-c-dialog |
The <dialog> element. |
.pl-c-dialog__header |
Title + close button row. |
.pl-c-dialog__title |
The heading (<h2>). |
.pl-c-dialog__close |
The close button (top-right ✕). |
.pl-c-dialog__body |
Main content. |
.pl-c-dialog__footer |
Action row (flex, right-aligned, top divider). |
Tokens consumed
--pl-color-{surface,surface-2,text,text-muted,border},
--pl-shadow-3, --pl-radius-{xl,md}, --pl-control-block-size,
--pl-space-{3,5}, --pl-text-lg, --pl-leading-tight,
--pl-duration-{1,2}, --pl-ease-standard.
Tokens exposed
| Token | Default | Purpose |
|---|---|---|
--pl-c-dialog-size |
42rem |
Max inline-size. Override per-dialog. |
Responsive sizing
inline-size: min(100% - 2rem, var(--pl-c-dialog-size)) - the dialog never
overflows its viewport (the 100% - 2rem gives 1rem gutters on each side).
max-block-size: min(100dvb - 2rem, 80dvb) + overflow: auto keeps tall
dialogs scrollable.
Enter / exit animation
The dialog animates with @starting-style (opacity + scale) and
transition-behavior: allow-discrete on overlay/display so the exit
transition runs (normally display: none kills transitions instantly).
Accessibility
- Modal focus trap: native -
showModal()traps focus inside the dialog until it closes. - Esc to close: native - pressing
Esccallsclose()and returns focus to the trigger. - Close button: provide a visible ✕ button; also close on footer actions.
- Semantics: the
<dialog>element has an implicitrole="dialog"andaria-modal="true"when shown viashowModal(). Addaria-labelledbypointing at the title<h2>’s id for explicit association.