HTML Tags

HTML <dialog> Tag

The <dialog> tag represents a dialog box or modal window that can contain interactive content such as text, forms, or buttons.
It can be opened or closed using the open attribute or JavaScript methods.
The <dialog> element is ideal for creating pop-ups, confirmation boxes, or form modals without external JavaScript libraries.

Syntax

<dialog open>
  Content goes here...
</dialog>

Attributes

AttributeDescription
openSpecifies that the dialog is currently open.
idAssigns a unique identifier to the dialog.
classSpecifies one or more class names for CSS styling.
styleApplies inline CSS styles.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Dialog Tag Example</title>
</head>
<body>
  <h1>Dialog Tag Example</h1>

  <!-- Dialog Element -->
  <dialog id="infoDialog">
    <p>This is a sample dialog box using the &lt;dialog&gt; tag.</p>
    <button id="closeBtn">Close</button>
  </dialog>

  <!-- Open Dialog Button -->
  <button id="openBtn">Open Dialog</button>

  <script>
    const dialog = document.getElementById("infoDialog");
    const openBtn = document.getElementById("openBtn");
    const closeBtn = document.getElementById("closeBtn");

    openBtn.addEventListener("click", () => dialog.showModal());
    closeBtn.addEventListener("click", () => dialog.close());
  </script>
</body>
</html>

Output

Browser Output

You’ll see a button labeled “Open Dialog”.
When clicked, a popup dialog box appears with text and a “Close” button.
Try this in our TryIt Editor to see how easily dialogs can be toggled.

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes❌No

All major browsers support <dialog> except of IE.

Notes

  • The dialog can be shown using .show() or .showModal() JavaScript methods.
  • Use the ::backdrop CSS pseudo-element to style the overlay behind a modal dialog.
  • The <dialog> element improves accessibility when used with focus management and ARIA roles.
  • It is not supported in Internet Explorer.

Conclusion

The <dialog> tag is a modern and semantic way to create modal windows or popups.
It simplifies implementation compared to traditional JavaScript modals and provides built-in accessibility and focus control.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend