<option> Tag in HTML
The <option> tag is used to define options in a drop-down list created using the <select> tag. Each <option> represents a single option that the user can choose from in the drop-down.
Key Points on <option> Tag:
- The <option> tag is used within the <select> element to define each item in a drop-down list.
- Each <option> can have text content, and an optional value attribute, which will be sent to the server when the form is submitted.
- The selected attribute can be used to pre-select an option.
- The disabled attribute can be used to disable an option in the list, making it unselectable.
- The label attribute can be used to provide a user-readable label for the option.
Syntax of <option> Tag:
Syntax Example
<select>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
Example of <option> Tag in HTML:
This example demonstrates how the <option>
tag is used within a <select>
tag to create a drop-down list.
Code Example
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Output
The <option>
tag is a key part of creating interactive forms in HTML, allowing users to select from a list of options. It is used in combination with the <select>
tag to create a drop-down menu, and it supports attributes like value
, selected
, and disabled
for better control over user interactions.