The HTML <option> tag
- Previous Page <optgroup>
- Next Page <output>
Definition and Usage
<option>
tag defines the options in the selection list.
<option>
The element is located in <select>,<optgroup> or <datalist> within the element.
Note:<option>
The tag can be used without any attributes, but you usually need the value attribute, which indicates the content sent to the server when the form is submitted.
Tip:If you have a long list of options, you can <optgroup> Group related options within a tag.
See also:
HTML DOM Reference Manual:Option Object
Instance
Example 1
A dropdown list containing four options:
<label for="cars">Please select a car brand:</label> <select id="cars"> <option value="audi">奥迪</option> <option value="byd">比亚迪</option> <option value="geely">吉利</option> <option value="volvo">Volvo</option> </select>
Example 2
in <datalist>
used in elements <option>
:
<label for="browser">Please select your browser from the list:</label> <input list="browsers" name="browser" id="browser"> <datalist id="browsers"> <option value="Edge"> <option value="Firefox"> <option value="Chrome"> <option value="Opera"> <option value="Safari"> </datalist>
Example 3
in <optgroup>
used in elements <option>
:
<label for="cars">Please select a car brand:</label> <select id="cars"> <optgroup label="中国车"> <option value="byd">比亚迪</option> <option value="geely">吉利</option> </optgroup> <optgroup label="德国车"> <option value="mercedes">奔驰</option> <option value="audi">奥迪</option> </optgroup> </select>
Attribute
Attribute | Value | Description |
---|---|---|
disabled | disabled | Specifies that the option should be disabled. |
label | Text | Specifies a shorter label for the option. |
selected | selected | Specifies that an option should be pre-selected when the page is loaded. |
value | Text | Specifies the value to be sent to the server. |
Global Attributes
<option>
The tag also supports Global Attributes in HTML.
Event Attributes
<option>
The tag also supports Event Attributes in HTML.
Default CSS Settings
None.
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page <optgroup>
- Next Page <output>