06 / 06

What is the <dialog> tag?

Understanding the <dialog> Tag in HTML

The <dialog> tag in HTML is used to create a dialog box or modal window that can be shown or hidden using JavaScript. It is a native HTML element that makes it easier to implement pop-up dialogs, confirmation boxes, and modal interfaces without needing external libraries.

Example of Using <dialog>
Key Points About <dialog>
  1. 1

    The <dialog> element represents a dialog box or modal window.

  2. 2

    dialog.show(): Opens the dialog as a non-modal (still allows background interaction).

  3. 3

    dialog.showModal(): Opens the dialog as a modal (blocks background interaction).

  4. 4

    dialog.close(): Closes the dialog.

  5. 5

    Simplifies implementing modals compared to custom JavaScript/CSS solutions.