HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: dialog

The <dialog> tag is a new HTML5 element that represents a dialog box or a modal window. It is used to display content that requires user interaction or input. The dialog box can be used for various purposes such as displaying messages, asking for confirmation, or getting user input.

Brief Explanation about HTML Tag: dialog

The <dialog> tag is a container element that can be used to create a dialog box or a modal window. The dialog box is displayed on top of the current page and requires user interaction before the user can continue with the page. The dialog box can be closed by the user or by using JavaScript.

The <dialog> tag has several attributes that can be used to customize the dialog box. The open attribute is used to specify whether the dialog box is open or closed. The close attribute is used to specify whether the dialog box can be closed by the user. The show attribute is used to specify whether the dialog box should be displayed immediately or after a certain event.

Code Examples in Per Tags

Here are some examples of how to use the <dialog> tag:

Example 1: Simple Dialog Box

This example shows a simple dialog box with a message and a close button:

<dialog>
  <p>This is a simple dialog box.</p>
  <button>Close</button>
</dialog>

Example 2: Dialog Box with User Input

This example shows a dialog box with a form that asks for the user's name and email:

<dialog>
  <form>
    <label>Name:</label>
    <input type="text" name="name">
    <br>
    <label>Email:</label>
    <input type="email" name="email">
    <br>
    <button>Submit</button>
  </form>
</dialog>

Example 3: Dialog Box with Custom Styling

This example shows a dialog box with custom styling using CSS:

<dialog style="background-color: #f2f2f2; border: 1px solid #ccc; padding: 10px;">
  <p>This is a dialog box with custom styling.</p>
  <button style="background-color: #4CAF50; color: white; padding: 5px 10px; border: none; border-radius: 3px;">Close</button>
</dialog>

Reference

Activity