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 1015707 of <option>

  • Revision slug: Web/HTML/Element/option
  • Revision title: <option>
  • Revision id: 1015707
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Updated for bug 1090602 by adding note about the changed behavior on e10s

Revision Content

{{HTMLRef}}

In a Web form, the HTML <option> element is used to create a control representing an item within a {{HTMLElement("select")}}, an {{HTMLElement("optgroup")}} or a {{HTMLElement("datalist")}} HTML5 element.

Content categories None.
Permitted content Text with eventually escaped characters (like &eacute;).
Tag omission The start tag is mandatory. The end tag is optional if this element is immediately followed by another <option> element or an {{HTMLElement("optgroup")}}, or if the parent element has no more content.
Permitted parent elements A {{HTMLElement("select")}}, an {{HTMLElement("optgroup")}} or a {{HTMLElement("datalist")}} element.
DOM interface {{domxref("HTMLOptionElement")}}

Attributes

This element includes the global attributes.

{{htmlattrdef("disabled")}}
If this Boolean attribute is set, this option is not checkable. Often browsers grey out such control and it won't receive any browsing event, like mouse clicks or focus-related ones. If this attribute is not set, the element can still be disabled if one its ancestors is a disabled {{HTMLElement("optgroup")}} element.
{{htmlattrdef("label")}}
This attribute is text for the label indicating the meaning of the option. If the label attribute isn't defined, its value is that of the element text content.
Usage note: the label attribute is designed to contain a short label typically used in a hierarchical menu. The value attribute describes a longer label designed to be used near a radio button, for example.
{{htmlattrdef("selected")}}
If present, this Boolean attribute indicates that the option is initially selected. If the <option> element is the descendant of a {{HTMLElement("select")}} element whose {{htmlattrxref("multiple", "select")}} attribute is not set, only one single <option> of this {{HTMLElement("select")}} element may have the selected attribute.
{{htmlattrdef("value")}}
The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is omitted, the value is taken from the text content of the option element.

Examples

See {{HTMLElement("select")}} for examples.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', 'the-button-element.html#the-option-element', '<option>')}} {{Spec2('HTML WHATWG')}}  
{{SpecName('HTML5 W3C', 'forms.html#the-option-element', '<option>')}} {{Spec2('HTML5 W3C')}}  
{{SpecName('HTML4.01', 'interact/forms.html#h-17.6', '<option>')}} {{Spec2('HTML4.01')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{CompatGeckoDesktop("1.0")}}[1][2] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}}[1] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

[1] Gecko doesn't display the value of the label attribute as option text if element's content is empty. See {{bug("1205213")}}.

[2] Historically, Firefox has allowed keyboard and mouse events to bubble up from the <option> element to the parent {{HTMLElement("select")}} element. This doesn't happen in Chrome, however, although this behavior is inconsistent across many browsers. For better Web compatibility (and for technical reasons), when Firefox is in multi-process mode and the <select> element is displayed as a drop-down list. The behavior is unchanged if the <select> is presented inline and it has either the multiple attribute defined or a size attribute set to more than 1. Rather than watching <option> elements for events, you should watch for {event("change")}} events on {{HTMLElement("select")}}. See {{bug(1090602)}} for details.

See also

  • Other form-related elements: {{HTMLElement("form")}}, {{HTMLElement("legend")}}, {{HTMLElement("label")}}, {{HTMLElement("button")}}, {{HTMLElement("select")}}, {{HTMLElement("datalist")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("textarea")}}, {{HTMLElement("keygen")}}, {{HTMLElement("input")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}} and {{HTMLElement("meter")}}.

Revision Source

<div>{{HTMLRef}}</div>

<p>In a Web form, the <strong>HTML<em> </em><code>&lt;option&gt;</code><em> </em>element</strong> is used to create a control representing an item within a {{HTMLElement("select")}}, an {{HTMLElement("optgroup")}} or a {{HTMLElement("datalist")}} HTML5 element.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row"><a href="/en-US/docs/Web/HTML/Content_categories">Content categories</a></th>
   <td>None.</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td>Text with eventually escaped characters (like <code>&amp;eacute;</code>).</td>
  </tr>
  <tr>
   <th scope="row">Tag omission</th>
   <td>The start tag is mandatory. The end tag is optional if this element is immediately followed by another <code>&lt;option&gt;</code> element or an {{HTMLElement("optgroup")}}, or if the parent element has no more content.</td>
  </tr>
  <tr>
   <th scope="row">Permitted parent elements</th>
   <td>A {{HTMLElement("select")}}, an {{HTMLElement("optgroup")}} or a {{HTMLElement("datalist")}} element.</td>
  </tr>
  <tr>
   <th scope="row">DOM interface</th>
   <td>{{domxref("HTMLOptionElement")}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p>This element includes the <a href="/en-US/docs/Web/HTML/Global_attributes">global attributes</a>.</p>

<dl>
 <dt>{{htmlattrdef("disabled")}}</dt>
 <dd>If this Boolean attribute is set, this option is not checkable. Often browsers grey out such control and it won't receive any browsing event, like mouse clicks or focus-related ones. If this attribute is not set, the element can still be disabled if one its ancestors is a disabled {{HTMLElement("optgroup")}} element.</dd>
 <dt>{{htmlattrdef("label")}}</dt>
 <dd>This attribute is text for the label indicating the meaning of the option. If the <code>label</code> attribute isn't defined, its value is that of the element text content.
 <div class="note"><em>Usage note: </em>the <code><strong>label</strong></code> attribute is designed to contain a short label typically used in a hierarchical menu. The <strong><code>value</code></strong> attribute describes a longer label designed to be used near a radio button, for example.</div>
 </dd>
 <dt>{{htmlattrdef("selected")}}</dt>
 <dd>If present, this Boolean attribute indicates that the option is initially selected. If the <code>&lt;option&gt;</code> element is the descendant of a {{HTMLElement("select")}} element whose {{htmlattrxref("multiple", "select")}} attribute is not set, only one single <code>&lt;option&gt;</code> of this {{HTMLElement("select")}} element may have the <code>selected</code> attribute.</dd>
 <dt>{{htmlattrdef("value")}}</dt>
 <dd>The content of this attribute represents the value to be submitted with the form, should this option be selected.&nbsp;If this attribute is omitted, the value is taken from the text content of the option element.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<p>See {{HTMLElement("select")}} for examples.</p>

<h2 id="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', 'the-button-element.html#the-option-element', '&lt;option&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'forms.html#the-option-element', '&lt;option&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'interact/forms.html#h-17.6', '&lt;option&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>Initial definition</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 (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.0")}}<sup>[1][2]</sup></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</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 Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.0")}}<sup>[1]</sup></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Gecko doesn't display the value of the <code>label</code> attribute as option text if element's content is empty. See {{bug("1205213")}}.</p>

<p>[2] Historically, Firefox has allowed keyboard and mouse events to bubble up from the <code>&lt;option&gt;</code> element to the parent {{HTMLElement("select")}} element. This doesn't happen in Chrome, however, although this behavior is inconsistent across many browsers. For better Web compatibility (and for technical reasons), when Firefox is in multi-process mode and the <code>&lt;select&gt;</code> element is displayed as a drop-down list. The behavior is unchanged if the <code>&lt;select&gt;</code> is presented inline and it has either the <code>multiple</code> attribute defined or a <code>size</code> attribute set to more than 1. Rather than watching <code>&lt;option&gt;</code> elements for events, you should watch for {event("change")}} events on {{HTMLElement("select")}}. See {{bug(1090602)}} for details.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Other form-related elements: {{HTMLElement("form")}}, {{HTMLElement("legend")}}, {{HTMLElement("label")}}, {{HTMLElement("button")}}, {{HTMLElement("select")}}, {{HTMLElement("datalist")}}, {{HTMLElement("optgroup")}}, {{HTMLElement("fieldset")}}, {{HTMLElement("textarea")}}, {{HTMLElement("keygen")}}, {{HTMLElement("input")}}, {{HTMLElement("output")}}, {{HTMLElement("progress")}} and {{HTMLElement("meter")}}.</li>
</ul>
Revert to this revision