Dialog (Native Modal) in HTML
From the HTML cheat sheet ยท Interactive & Web Components ยท verified Jul 2026
Dialog (Native Modal)
Native modal and non-modal dialogs without JavaScript libraries
html
<!-- Modal dialog -->
<dialog id="confirm-dialog">
<h2>Confirm Action</h2>
<p>Are you sure you want to proceed?</p>
<form method="dialog">
<button value="cancel">Cancel</button>
<button value="confirm">Confirm</button>
</form>
</dialog>
<button onclick="document.getElementById('confirm-dialog').showModal()">
Open Modal
</button>๐ก <dialog> with showModal() gives you backdrop, focus trapping, and Escape-to-close for free
โก form method="dialog" auto-closes the dialog on submit โ no JavaScript close handler needed
๐ Style the backdrop with dialog::backdrop โ supports background, blur, and animations
๐ข Replaces most uses of modal libraries โ native, accessible, and lightweight
dialogmodalinteractive