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

More HTML tasks

Back to the full HTML cheat sheet