Description
The HTML element <option>
is used to define an option in the dropdown list of the <select>
element.
A dropdown list must contain at least one <option>
element.
The below table summarizes its usage.
Usage Details | |
Placement | Parent element is <select> if the <optgroup> element is not used, else the parent is the <optgroup> element.It is defined as an Inline element. |
Contents | It can contain text. |
Tags | The opening tag is required, but the closing tag is optional. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <option>
element.
<option value="option-value">...</option>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element option</title>
</head>
<body>
<form>
<select>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="papaya">Papaya</option>
</select>
</form>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <option>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <option> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <option> supports the HTML Global Attributes. |
Event Attributes | The tag <option> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <option>
element.
Attribute | Value | Required | Description |
label |
text | No | Specifies a short label for an option. |
disabled |
disabled |
No | Boolean attribute that indicates that the enclosed option is disabled i.e. the option is not selectable. |
selected |
selected |
No | Boolean attribute that indicates that the option is initially selected. |
value |
option-value | No | Defines a value for an option. If it is not defined, the value of an <option> element is the text content of the element. |
Browser Compatibility
The tag <option>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 2.1+