HTML tagForms

<option>

A single option in a `<select>` list, or a suggestion in a `<datalist>`.

Display
block
Closing tag
Required
Permitted content
Text
On this page

Example

#
HTML
<label for="city">Workshop city</label>
<select id="city" name="city">
  <option value="chi">Chicago</option>
  <option value="aus" selected>Austin</option>
  <option value="sea" disabled>Seattle (no seats left)</option>
</select>
Preview

Definition and usage

#

The <option> element represents one item you can choose. It usually sits inside <select> or <optgroup>, and inside <datalist> it acts as a suggestion for a text field.

The text between the tags is what the user sees, and the value attribute is the value sent to the server. Thanks to this, you can show "Seattle" while sending the short code sea. If you leave out value, the option’s text is sent instead.

You select an option from the start with the selected attribute, or block it with disabled. The closing </option> tag can technically be omitted, but it’s worth writing anyway.

Syntax

#
Syntax
<option value="value">Option text</option>

Attributes

#
  • value

    text

    The value sent with the form when this option is chosen. Without this attribute, the option’s text is sent.
  • selected

    boolean attribute

    Selects the option once the page loads. If you mark several options this way in a list without multiple, the browser only keeps the last one selected. When you mark none, the first available option is selected.
  • disabled

    boolean attribute

    Shows the option but doesn’t let you choose it. Useful for sold-out dates or features available only on a higher plan.
  • label

    text

    A label for the option used instead of its content. Rarely needed in practice, since the text between the tags is usually enough on its own.

The element also supports all global attributes, such as class, id, style and hidden.

Attributes in practice

#

value

text

The value sent with the form when this option is chosen. Without this attribute, the option’s text is sent.

HTML
<select name="level" aria-label="Level">
  <option value="1">Beginner</option>
  <option value="2">Intermediate</option>
  <option value="3">Advanced</option>
</select>
Preview

selected

boolean attribute

Selects the option once the page loads. If you mark several options this way in a list without multiple, the browser only keeps the last one selected. When you mark none, the first available option is selected.

HTML
<select name="plan" aria-label="Plan">
  <option value="monthly">Monthly</option>
  <option value="yearly" selected>Yearly</option>
</select>
Preview

disabled

boolean attribute

Shows the option but doesn’t let you choose it. Useful for sold-out dates or features available only on a higher plan.

HTML
<select name="date" aria-label="Date">
  <option>October 12</option>
  <option disabled>October 19 (no seats left)</option>
  <option>October 26</option>
</select>
Preview

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Write value values in a stable, short form, for example as codes or ids. You can then freely change the option’s text without breaking the server-side code.
  • A hint option like "Choose…" should have value="", with the list itself carrying the required attribute.

Related entries

#

Spotted a mistake or missing an example? Write to us.