<dialog> Tag in HTML

The <dialog> tag represents a dialog box or a pop-up window in HTML. It is a block-level element that is used to create modal and non-modal dialog boxes, which can be useful for alerts, forms, or additional information. This tag has a built-in open/close functionality and can be styled and controlled using JavaScript.

Key Points on <dialog> Tag:

Syntax of <dialog> Tag:

Syntax Example

<dialog open>
            <p>This is a dialog box.</p>
        </dialog>

Example of <dialog> Tag in HTML:

This example shows how to create a dialog box with the <dialog> tag and control it using JavaScript.

Code Example


        <button onclick="document.getElementById('myDialog').showModal()">Open Dialog</button>
        
        <dialog id="myDialog">
            <p>This is a dialog box!</p>
            <button onclick="document.getElementById('myDialog').close()">Close</button>
        </dialog>
                

Output

This is a dialog box!

The <dialog> tag is especially useful for creating native-looking pop-ups without relying on external libraries. It is supported in most modern browsers, though polyfills may be needed for full compatibility in older browsers.