- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- 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 Color Names & Values
- HTML - Color Names
- 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 Picker
- HTML References
- HTML - Cheat Sheet
- 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
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.
Syntax
<dialog>.....</dialog>
Attribute
HTML data tag supports Global and Event attributes of HTML. Accept a specific attribute as well which is listed below.
Attribute | Value | Description |
---|---|---|
open | open | Indicates that the dialog is active and can be interacted with. |
Examples of HTML dialog Tag
Bellow examples will illustrate the usage of dialog tag. Where, when and how to use dialog tag to create dialog box, alert box, or subwindow.
Creating Dialog Box
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>
Default Open Dialog Box
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>
Styling Dialog Box
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>
Creating a Form in Dialog Box
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>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
dialog | Yes 37.0 | Yes 79.0 | Yes 98.0 | Yes 15.4 | Yes 24.0 |
To Continue Learning Please Login
Login with Google