HTML: <option> tag
This HTML tutorial explains how to use the HTML element called the <option> tag with syntax and examples.
Description
The HTML <option> tag creates an item in a <select>, <datalist> or <optgroup> tag. The item defined by the <option> tag will appear as one of the values in a list of values. This tag is also commonly referred to as the <option> element.
Syntax
In HTML, the syntax for the <option> tag is:
<body>
<label for="tutorial_choice">Tutorials: </label>
<select id="tutorial_choice">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="sql">SQL</option>
</select>
</body>
Sample Output
Attributes
In addition to the Global Attributes, the following is a list of attributes that are specific to the <option> tag:
Attribute | Description | HTML Compatibility |
---|---|---|
disabled | Boolean value indicating that the user cannot interact with the option. | HTML 4.01, HTML5 |
label | The label that describes in the option in the dropdown list. If the label is not provided, the value attribute will be used instead. |
HTML 4.01, HTML5 |
selected | Boolean value indicating whether this option is initially selected. By default, only one option can have the selected attribute. However, if the multiple attribute is set on the <select> tag, then more than one <option> can have the selected attribute. |
HTML 4.01, HTML5 |
value | The value sent when the form is submitted if the option has been selected in the dropdown list. | HTML 4.01, HTML5 |
Note
- The HTML <option> element is found within the <body> tag. The <option> tag is usually found within the <select>, <datalist> or <optgroup> tags.
Browser Compatibility
The <select> tag has basic support with the following browsers:
- Chrome
- Android
- Firefox (Gecko)
- Firefox Mobile (Gecko)
- Internet Explorer (IE)
- Edge Mobile
- Opera
- Opera Mobile
- Safari (WebKit)
- Safari Mobile
Example
We will discuss the <select> tag below, exploring examples of how to use the <select> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.
Advertisements