What is <option> element in HTML?
In HTML, the <option> element is used to display a menu or popup item. The items are defined in a <select>, <optgroup>, or <datalist> element.
Syntax
<option label="" value="" selected disabled> option content </option>
Where:
label: It takestextas value. It specifies a shorter label that indicates the meaning of the option. In case thelabelis undefined, its value is the content of the<option>element.value: It takestextas value. It specifies the value that is submitted with the form to the server. In case thevalueis undefined, its value is the content of the<option>element.selected: It is aBooleanattribute that specifies that an option is selected when loading the page.disabled: It is aBooleanattribute that specifies that an<option>is disabled. The<option>is not selectable if it is set. This makes browsers unable to receive focus-related events like mouse clicks.
In case the
<option>element is the descendant of a<select>element, only one single<option>of this<select>element may have theselectedattribute, ifmultipleattributes of<select>is not set.
Example
The following code demonstrates the usage of <option> element in HTML.
The content we want to be displayed as option is written within the opening and closing tags <option> and </option>.