What is <dialog> element in HTML?

The <dialog> element is used to define a dialog box, interactive component, or subwindow in a webpage. It allows the user to create popup dialogs and windows. The text to be shown in a dialog box is enclosed within <dialog> and </dialog> tags.

Attributes

The <dialog> tag supports global attributes, attributes common to all HTML elements (e.g. class, id, lang, title, etc.) It also supports event attributesattributes connected to action events (e.g., user clicks a piece of text.)
An important additional attribute is open. This tag indicates whether the dialog will be shown to the user of the webpage. When this attribute is not set, the dialog will not be shown to the user.

Code

The following code snippet shows how the <dialog> tag is used to create a dialog box.

Copyright ©2024 Educative, Inc. All rights reserved