HTML5 <option> Tag

The HTML <option> tag is used to create a control representing an item within a <select>, an <optgroup> or a <datalist> HTML5 element.

The only content permitted inside this element is text with eventually escaped characters (like &eacute;). The start tag is mandatory for this element. The end tag is optional if this element is immediately followed by another <option> element or an <optgroup>, or if the parent element has no more content. The parent of the <option> tag can only be a <select>, an <optgroup> or a <datalist> element.

Here is an example of using this tag:

<p>Which course would you like to watch today?</p>
<p><label>Course:
  <select name="c">
    <optgroup label="8.01 Physics I: Classical Mechanics">
      <option value="8.01.1">Lecture 01: Powers of Ten</option>
      <option value="8.01.2">Lecture 02: 1D Kinematics</option>
      <option value="8.01.3">Lecture 03: Vectors</option>
    </optgroup>
    <optgroup label="8.02 Electricity and Magnestism">
      <option value="8.02.1">Lecture 01: What holds our world together?</option>
      <option value="8.02.2">Lecture 02: Electric Field</option>
      <option value="8.02.3">Lecture 03: Electric Flux</option>
    </optgroup>
    <optgroup label="8.03 Physics III: Vibrations and Waves">
      <option value="8.03.1">Lecture 01: Periodic Phenomenon</option>
      <option value="8.03.2">Lecture 02: Beats</option>
      <option value="8.03.3">Lecture 03: Forced Oscillations with Damping</option>
    </optgroup>
  </select>
</label></p>

Attributes

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 <optgroup> element.

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.

selected

If present, this Boolean attribute indicates that the option is initially selected. If the <option> element is the descendant of a <select> element whose multiple attribute is not set, only one single <option> of this <select> element may have the selected attribute.

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 the Pen HTML option Tag by Tutorialio (@tutorialio) on CodePen.

Further Reading

  1. Read more about the HTML <option> element on MDN.
  2. You can also read the HTML <option> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top