HTML5
HTML5

HTML Dialog

<dialog> represents a dialog box or modal window. It is useful for things like a confirmation message, a small form, or extra information that should appear above the page. A dialog can be shown as a normal part of the page with the open attribute, or JavaScript can open it as a modal with showModal(). The HTML element provides the structure. JavaScript is commonly used when your application needs to decide when the dialog should open or close.

Why this matters

  • ·Dialog gives modal content a native HTML element.
  • ·It provides a clear semantic role for a dialog.
  • ·It can work with forms and buttons.

Common mistakes

  • ·A dialog does not automatically open as a modal just because you wrote the tag.
  • ·Important information should not be hidden inside a dialog without a good reason.
  • ·Always provide a clear way to close an interactive dialog.
Your codeHTML
Live preview

Frequently asked questions

It represents a dialog box or modal-style piece of content.

Practice questions

Question 1

Create an open dialog with a close button.

Your codeHTML
Live preview

Question 2

Create a dialog containing a confirmation message.

Your codeHTML
Live preview

Quick check

Just for this topic answer honestly, then check yourself.

1 / 3

Which tag represents a dialog box?