A native dialog opened with showModal()provides modal semantics, moves focus inside, and makes the rest of the page inert. Give it an accessible name and choose an appropriate initial focus. A popover is non-modal and does not automatically provide dialog or menu semantics.
<button type="button" id="open-confirmation" hidden>
Review deletion
</button>
<a href="/invoices/123/delete/" id="confirmation-fallback">
Review deletion on a separate page
</a>
<dialog id="confirm-delete" aria-labelledby="confirm-delete-title">
<form method="dialog">
<h2 id="confirm-delete-title">Delete this invoice permanently?</h2>
<p>This cannot be undone.</p>
<button type="submit" value="cancel" autofocus>Cancel</button>
<button type="submit" value="confirm">Delete</button>
</form>
</dialog>
const trigger = document.getElementById('open-confirmation');
const dialog = document.getElementById('confirm-delete');
const fallback = document.getElementById('confirmation-fallback');
if (trigger && dialog && fallback && typeof dialog.showModal === 'function') {
trigger.addEventListener('click', () => {
dialog.returnValue = '';
dialog.showModal();
});
dialog.addEventListener('close', () => {
trigger.focus();
});
trigger.hidden = false;
fallback.hidden = true;
}
The fallback URL represents a server-rendered confirmation page; replace it with a real route. Without JavaScript, that link remains available. This example only returns a choice: method="dialog"closes the dialog without sending a request. Only an explicitconfirm result should lead to an authorised server-side deletion. Cancel and Escape must never delete anything.
The close handler restores focus explicitly, including after pointer activation in browsers that do not focus buttons when clicked. If a completed action removes the trigger, move focus to the next logical control instead.
See W3C's native dialog technique for focus, naming, and keyboard expectations.
Declarative dialog commands
Where your tested browser baseline supports invoker commands,commandfor identifies the dialog and commandsupplies the action. This supplementary help dialog opens and closes without a JavaScript click handler:
<button type="button" commandfor="export-help" command="show-modal">
Export help
</button>
<dialog id="export-help" aria-labelledby="export-help-title">
<h2 id="export-help-title">Exporting your invoices</h2>
<p>Choose a date range, then select Download CSV.</p>
<button type="button" commandfor="export-help" command="close" autofocus>
Close
</button>
</dialog>
For older browsers, use the guarded showModal()enhancement and page fallback above. Test command support with'commandForElement' in HTMLButtonElement.prototype; support for dialog alone is not enough. Do not attach both a declarative opener and an unconditional JavaScript opener.
Support checked 4 October 2026: invoker commands are Baseline Newly available. Check newer additions separately: closedby still has limited availability. It controls dismissal behaviour; it does not replace an accessible name or a visible Cancel or Close control.