dialog
The native dialog container.
Learn Dialog Element with practical examples for rich HTML features, native browser behavior, accessibility, performance, SEO and live practice.
HTML advanced
Dialog is a native element for popups, confirmations, small forms and modal interactions.
A dialog can be opened with JavaScript using show() for non-modal behavior or showModal() for a modal that places the rest of the page behind a backdrop.
Native dialog is useful, but you still need clear labels, focus behavior, close buttons and a reason to interrupt the user.
The native dialog container.
Opens a modal dialog.
Closes the dialog.
CSS pseudo-element for the modal background layer.
Syntax and behavior
A modal without an obvious close path quickly becomes frustrating.
<button type="button" id="open">Open details</button> <dialog id="course-dialog" aria-labelledby="dialog-title"> <h2 id="dialog-title">Course details</h2> <p>This modal explains the next step.</p> <button type="button" id="close">Close</button> </dialog>
<dialog open> <p>Click somewhere maybe.</p> </dialog>
Rules that matter
These elements can create rich interfaces, but they still need clear purpose, safe fallbacks and production discipline.
Do not turn every small hint into a modal.
Use a heading and connect it with aria-labelledby when useful.
A visible close or cancel button is expected.
Dialog forms can use method="dialog" for local dialog actions.
The backdrop should support focus and visual context.
Opening, focusing and closing must feel predictable.
Production thinking
This matters because modals affect attention. Native dialog gives you better defaults, but design judgment still matters.
Native modal dialog handles a lot, but labels, initial focus and clear close behavior still matter.
Use dialog for confirmations, short forms and focused tasks. Avoid giant multi-screen modals.
Critical page content should not exist only inside a dialog that users may never open.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.