- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <dialog> tag
The HTML <dialog> tag is used to represent the dialog box, alert box, or subwindow.
It has an attribute named open, which indicates that the dialog is active and can be interacted with. If the open attribute is not set, the dialog box will not appear on the screen view, and the user cannot see it.
You can use the dialog element to give some alert messages to the user on clicking any form button.
Following are the supported attributes of the HTML <dialog> tag −
S.No | Attribute & Description |
---|---|
1 | open Indicates that the dialog is active and can be interacted with |
Syntax
Following is the syntax of the <dialog> tag −
<dialog>.....</dialog>
Example
The following program illustrates the use of the HTML <dialog> tag. We are not using an 'open' attribute inside <dialog> tag. So after the execution of the program, no dialog box will be displayed because, by default, it is closed.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML dialog box</title> </head> <body> <!--create a dialog element--> <p>Example of the HTML 'dialog' element</p> <dialog>Alert</dialog> </body> </html>
When we run the above code, it will generate an output consisting of the text displayed on the webpage.
Example
Following is another example of the HTML <dialog> box. Here, we are creating a dialog box using the <dialog> tag. We use the ‘open’ attribute inside the ‘dialog’ element, so when we execute the program a dialog box will be displayed on the screen view.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML dialog box</title> </head> <body> <p>Example of the HTML 'dialog' element</p> <!--create a dialog element--> <dialog open>Dialog box!</dialog> </body> </html>
On running the above code, the output window will pop up, consisting of text along with a dialog box displayed on the webpage.
Example
In the following example, we are creating a dialog box using the HTML <dialog> tag. We use the CSS to style the created dialog box.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML dialog box</title> <style> dialog { width: 100px; height: 50px; background-color: red; color: white; display: grid; place-items: center; border-radius: 5px; } </style> </head> <body> <p>Example of the HTML 'dialog' element</p> <!--create a dialog element--> <dialog open>Alert box!</dialog> </body> </html>
When we run the above code, it will generate an output displaying the text along with a CSS applied to it on the webpage.
Example
In this example, we are using the HTML <dialog> tag to create a dialog box, and we create a "form" within the dialog element that contains a button named "OK", the dialog box will disappear when the user clicks on the OK button.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML dialog box</title> <style> dialog { background-color: red; color: white; } </style> </head> <body> <p>Example of the HTML 'dialog' element</p> <!--create a dialog element--> <dialog open> <p>Warning!</p> <form method="dialog"> <button>Ok</button> </form> </dialog> </body> </html>
When we run the above code, it will generate an output displaying the text along with a dialog box and a button on the webpage.