Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 717707 of <dialog>

  • Revision slug: Web/HTML/Element/dialog
  • Revision title: <dialog>
  • Revision id: 717707
  • Created:
  • Creator: jsx
  • Is current revision? No
  • Comment Updated compatibility table

Revision Content

{{ SeeCompatTable() }}

Summary

The HTML <dialog> element represents a dialog box or other interactive component, such as an inspector or window. <form> elements can be integrated within a dialog by specifying them with the attribute method="dialog". When such a form is submitted, the dialog is closed with a returnValue attribute set to the value of the submit button used.

The {{cssxref('::backdrop')}} CSS pseudo-element can be used to style behind a <dialog> element, for example to dim inaccessible content whilst a modal dialog is active.

Attributes

This element includes the global attributes. The tabindex attribute must not be used on the <dialog> element.

{{htmlattrdef("open")}}
Indicates that the dialog is active and available for interaction. When the open attribute is not set, it shouldn't be shown to the user.

Examples

Example 1

<dialog open>
  <p>Greetings, one and all!</p>
</dialog>

Example 2

<!-- Simple pop-up dialog box, containing a form -->
<dialog id="favDialog">
  <form method="dialog">
    <section>
      <p><label for="favAnimal">Favorite animal:</label>
      <select id="favAnimal" name="favAnimal">
        <option></option>
        <option>Brine shrimp</option>
        <option>Red panda</option>
        <option>Spider monkey</option>
      </select></p>
    </section>
    <menu>
      <button id="cancel" type="reset">Cancel</button>
      <button type="submit">Confirm</button>
    </menu>
  </form>
</dialog>

<menu>
  <button id="updateDetails">Update details</button>
</menu>

<script>
  (function() {
    var updateButton = document.getElementById('updateDetails');
    var cancelButton = document.getElementById('cancel');

    // Update button opens a modal dialog
    updateButton.addEventListener('click', function() {
      document.getElementById('favDialog').showModal();
    });

    // Form cancel button closes the dialog box
    cancelButton.addEventListener('click', function() {
      document.getElementById('favDialog').close();
    });

  })();
</script>

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'forms.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML5.1')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 37 {{CompatNo()}} {{bug(840640)}} {{CompatNo()}} 24 {{CompatNo()}}
Anchor points {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support Android Browser 37 {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}
Anchor points {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}} {{CompatNo()}}

See also

{{HTMLRef}}

Revision Source

<p>{{ SeeCompatTable() }}</p>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <strong>HTML <code>&lt;dialog&gt;</code> element</strong> represents a dialog box or other interactive component, such as an inspector or window. <code>&lt;form&gt;</code> elements can be integrated within a dialog by specifying them with the attribute <code>method="dialog"</code>. When such a form is submitted, the dialog is closed with a <code>returnValue</code> attribute set to the <code>value</code> of the submit button used.</p>
<p>The {{cssxref('::backdrop')}} CSS pseudo-element can be used to style behind a <code>&lt;dialog&gt;</code> element, for example to dim inaccessible content whilst a modal dialog is active.</p>
<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a>, <a href="/en-US/docs/Web/HTML/Sections_and_Outlines_of_an_HTML5_document#Sectioning_roots">sectioning root</a></li>
 <li><dfn>Permitted content</dfn> <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">Flow content</a></li>
 <li><dfn>Tag omission</dfn> {{no_tag_omission}}</li>
 <li><dfn>Permitted parent elements</dfn> Any element that accepts <a href="/en-US/docs/HTML/Content_categories#Flow_content" title="HTML/Content categories#Flow content">flow content</a></li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLDialogElement")}}</li>
</ul>
<h2 id="Attributes" name="Attributes">Attributes</h2>
<p>This element includes the <a href="/en-US/docs/HTML/Global_attributes" title="HTML/Global attributes">global attributes</a>. The <code>tabindex</code> attribute must not be used on the <code>&lt;dialog&gt;</code> element.</p>
<dl>
 <dt>
  {{htmlattrdef("open")}}</dt>
 <dd>
  Indicates that the dialog is active and available for interaction. When the open attribute is not set, it shouldn't be shown to the user.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<h3 id="Example_1">Example 1</h3>
<pre class="brush: html">
&lt;dialog open&gt;
  &lt;p&gt;Greetings, one and all!&lt;/p&gt;
&lt;/dialog&gt;
</pre>
<h3 id="Example_2">Example 2</h3>
<pre class="brush: html">
&lt;!-- Simple pop-up dialog box, containing a form --&gt;
&lt;dialog id="favDialog"&gt;
  &lt;form method="dialog"&gt;
    &lt;section&gt;
      &lt;p&gt;&lt;label for="favAnimal"&gt;Favorite animal:&lt;/label&gt;
      &lt;select id="favAnimal" name="favAnimal"&gt;
        &lt;option&gt;&lt;/option&gt;
        &lt;option&gt;Brine shrimp&lt;/option&gt;
        &lt;option&gt;Red panda&lt;/option&gt;
        &lt;option&gt;Spider monkey&lt;/option&gt;
      &lt;/select&gt;&lt;/p&gt;
    &lt;/section&gt;
    &lt;menu&gt;
      &lt;button id="cancel" type="reset"&gt;Cancel&lt;/button&gt;
      &lt;button type="submit"&gt;Confirm&lt;/button&gt;
    &lt;/menu&gt;
  &lt;/form&gt;
&lt;/dialog&gt;

&lt;menu&gt;
  &lt;button id="updateDetails"&gt;Update details&lt;/button&gt;
&lt;/menu&gt;

&lt;script&gt;
  (function() {
    var updateButton = document.getElementById('updateDetails');
    var cancelButton = document.getElementById('cancel');

    // Update button opens a modal dialog
    updateButton.addEventListener('click', function() {
      document.getElementById('favDialog').showModal();
    });

    // Form cancel button closes the dialog box
    cancelButton.addEventListener('click', function() {
      document.getElementById('favDialog').close();
    });

  })();
&lt;/script&gt;
</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'forms.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '&lt;dialog&gt;')}}</td>
   <td>{{Spec2('HTML5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Chrome</th>
    <th>Firefox (Gecko)</th>
    <th>Internet Explorer</th>
    <th>Opera</th>
    <th>Safari</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>37</td>
    <td>{{CompatNo()}} {{bug(840640)}}</td>
    <td>{{CompatNo()}}</td>
    <td>24</td>
    <td>{{CompatNo()}}</td>
   </tr>
   <tr>
    <td>Anchor points</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
  </tbody>
 </table>
</div>
<div id="compat-mobile">
 <table class="compat-table">
  <tbody>
   <tr>
    <th>Feature</th>
    <th>Android</th>
    <th>Firefox Mobile (Gecko)</th>
    <th>IE Mobile</th>
    <th>Opera Mobile</th>
    <th>Safari Mobile</th>
   </tr>
   <tr>
    <td>Basic support</td>
    <td>Android Browser 37</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
   <tr>
    <td>Anchor points</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
    <td>{{CompatNo()}}</td>
   </tr>
  </tbody>
 </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
 <li><a href="/en-US/docs/Web/Guide/HTML/Forms" title="/en-US/docs/Web/Guide/HTML/Forms">HTML forms guide</a>.</li>
</ul>
<div>
 {{HTMLRef}}</div>
Revert to this revision