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

  • Revision slug: Web/HTML/Element/option
  • Revision title: <option>
  • Revision id: 738121
  • Created:
  • Creator: webmariner
  • Is current revision? No
  • Comment

Revision Content

Summary

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")}} 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')}}  

Browser compatibility

{{CompatibilityTable}}

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

Gecko notes

[1] Prior to Gecko 7.0, {{geckoRelease("7.0")}}, the label attribute incorrectly returned an empty string if not defined, instead of returning the element text content.

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")}}.

{{HTMLRef}}

Revision Source

<h2 id="Summary">Summary</h2>

<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>

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/Web/HTML/Content_categories" title="HTML/Content_categories">Content categories</a></dfn> None.</li>
 <li><dfn>Permitted content</dfn> Text with eventually escaped characters (like <code>&amp;eacute;</code>).</li>
 <li><dfn>Tag omission</dfn> The <span title="syntax-start-tag">start tag</span> is mandatory. The <span title="syntax-end-tag">end tag</span> 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.</li>
 <li><dfn>Permitted parent elements</dfn> A {{HTMLElement("select")}}, an {{HTMLElement("optgroup")}} or a {{HTMLElement("datalist")}} element.</li>
 <li><dfn>DOM interface</dfn> {{domxref("HTMLOptionElement")}}</li>
</ul>

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

<p><span style="line-height: 21px;">This element includes the&nbsp;</span><a href="/en-US/docs/Web/HTML/Global_attributes" style="line-height: 21px;" title="HTML/Global attributes">global attributes</a><span style="line-height: 21px;">.</span></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><strong>label</strong></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 <strong>selected</strong> 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")}} examples.</p>

<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', '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>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="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>{{CompatGeckoMobile("1.0")}} [1]</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")}} [1]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h3 id="Gecko_notes">Gecko notes</h3>

<p>[1] Prior to Gecko 7.0, {{geckoRelease("7.0")}}, the label attribute incorrectly returned an empty string if not defined, instead of returning the element text content.</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>

<p>{{HTMLRef}}</p>
Revert to this revision