HTML Reference Β· Forms
The <option> element
Reference for the HTML <option> element: choices in a select and suggestions in a datalist, the value, label, selected and disabled attributes, and technical details.
The <option> element is one choice inside a <select> or <optgroup>, or one suggestion inside a <datalist>. Its text is what the user sees; its value is what gets submitted. If there is no value, the text is submitted instead.
HTML
<label for="lang">Language</label> <select id="lang" name="lang"> <option value="en">English</option> <option value="pt" selected>PortuguΓͺs</option> </select>
Try it
Attributes
| Attribute | Values | Description |
|---|---|---|
value |
Text | The value submitted when this option is selected. Defaults to the option's text, with surrounding whitespace removed and inner whitespace collapsed. |
label |
Text | A label for the option. When present, browsers display it instead of the text content. |
selected |
Boolean | The option is selected when the page loads (and after a form reset). In a single select, only one option should have it. |
disabled |
Boolean | The option can't be chosen. Options inside a disabled <optgroup> are disabled too. |
It also accepts the global attributes.
Usage notes
- Text for people,
valuefor the server. Keep values stable codes (pt,pro) so you can reword the visible text later without breaking the backend. - Default selection. Without any
selected, a drop-down starts on its first non-disabled option. A select withmultiplestarts with nothing selected. selectedis only the default. Changing it in a script withsetAttributeaffects the reset state; setoption.selected = trueorselect.valueto change the current choice.- Placeholder options. A first option with
value=""("Chooseβ¦") plusrequiredon the select forces a real choice. - Plain text inside. In a classic select, an option holds text only; markup inside is ignored. The newer customizable select lets options contain richer content, but only where supported.
- In a datalist, the
valueis what gets inserted into the input; the text orlabelmay be shown as a hint.
Technical summary
| Content categories | None |
| Permitted content | If it has a label attribute and a value attribute: nothing. If it has a label but no value: text. Otherwise: text (customizable select allows phrasing content) |
| Tag omission | The end tag can be omitted if the option is immediately followed by another <option>, an <optgroup> or an <hr>, or if there is no more content in the parent element |
| Permitted parents | <select>, <datalist> or <optgroup> |
| Implicit ARIA role | option |
| DOM interface | HTMLOptionElement |
| Default display | block |
Browser support
Supported in every browser.
Related
<select>β the list the options belong to<optgroup>β grouping options under a heading<datalist>β suggestions for an input- Lesson: Drop-downs and Suggestions