HTML <option> Tag
- The HTML
<option>
tag defines an option in a dropdown list in an HTML form. - It is used in conjunction with the
<select>
element and can have various attributes set to specify the value, label, and selected state.
Syntax
The basic syntax for the <option>
tag is as follows:
<select>
<option value="value1">Option 1</option>
<option value="value2">Option 2</option>
<option value="value3" selected>Option 3</option>
</select>
In this code example, we have created a dropdown list with three options. The value
attribute specifies the value of the option, which is sent back to the server when the form is submitted. The text between the opening and closing tags is used to label the option. The selected
attribute is used to pre-select an option when the page loads.