Select
Use the <select>
element to provide a dropdown menu of options.
Usage
Include a set of <option>
elements with choices.
<label for="wizard">Who is the best wizard?</label>
<select id="wizard" name="wizard">
<option>Merlin</option>
<option>Gandalf</option>
<option>Radagast</option>
</select>
Values
The <option>
element can include a [value]
attribute. If not, its text content becomes the value when selected.
<label for="wizard">Who is the best wizard?</label>
<select id="wizard" name="wizard">
<option value="merlin">Merlin the Wise</option>
<option value="gandalf">Gandalf the Gray</option>
<option value="radagast">Radagast the Brown</option>
</select>
Selected by Default
Add the [selected]
attribute to an <option>
element to have it selected by default.
If not [selected]
is included, the first option is selected by default. If multiple elements have the [selected]
attribute, the last one in the DOM is selected.
<label for="wizard">Who is the best wizard?</label>
<select id="wizard" name="wizard">
<option value="merlin">Merlin the Wise</option>
<option value="gandalf">Gandalf the Gray</option>
<option value="radagast" selected>Radagast the Brown</option>
</select>