HTML <select>
Tag Tutorial
The <select>
tag in HTML is used to create a drop-down list of options for the user to choose from. This can be useful for forms, where you want the user to select an option from a list of choices.
Usage:
To create a <select>
element in your HTML document, you need to use the following syntax:
<select>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
In this example, we have three options within the <select>
element. The <option>
tag is used to define each option, and the value
attribute specifies the value of each option. The text between the opening and closing <option>
tags is what is displayed to the user in the drop-down list.
Main Attributes of the <select>
Tag:
Attribute | Description |
---|---|
name |
Specifies the name of the select element. This is used when submitting a form for the selected option. |
id |
Specifies a unique id for the select element. |
multiple |
Allows the user to select multiple options from the list. When this attribute is present, the user can use Ctrl (Windows) or Command (Mac) to select multiple options. |
size |
Specifies the number of visible options in the list. |
Example:
<select name="cars" id="carSelect">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>