<select>
A dropdown list the user picks one or more options from.
- Display
- inline-block
- Closing tag
- Required
- Permitted content
- Elements
<option>and<optgroup>
Example
#<label for="lang">Course language</label>
<select id="lang" name="lang">
<option value="pl" selected>Polish</option>
<option value="en">English</option>
<option value="de">German</option>
</select>Definition and usage
#The <select> element creates a choice list. You write the options as <option> elements, and you can group related options inside <optgroup>. When the form is submitted, the server receives the name=value pair of the chosen option.
A dropdown list saves space when there are many options: country, state, course language. With two or three options, radio buttons are often more convenient, because you can see every choice right away, without clicking anything.
With the multiple attribute, the list turns into a box where you can select several options (on a computer, by holding Ctrl or Cmd). This isn’t always intuitive, so for a multiple choice, consider a set of checkbox fields instead.
Syntax
#<select name="name">
<option value="a">Option A</option>
<option value="b">Option B</option>
</select>Attributes
#name
text
The name the chosen option’s value is sent to the server under. A list withoutnamewon’t be sent.boolean attribute
Lets you select several options. The list then displays as a scrollable box instead of a dropdown menu, and the server receives a separatename=valuepair for each selected option.number
The number of visible rows in the list. A value greater than 1 turns the dropdown menu into a fixed list box, even withoutmultiple.boolean attribute
Requires an option with a non-empty value to be selected. A popular pattern is a first option with an emptyvalue, for example "Choose a city…", which acts as a hint and fails validation.boolean attribute
Disables the entire list. The value of a disabled list isn’t sent with the form.
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#multiple
boolean attributeLets you select several options. The list then displays as a scrollable box instead of a dropdown menu, and the server receives a separate name=value pair for each selected option.
<label for="topics">What are you interested in?</label><br>
<select id="topics" name="topics" multiple>
<option value="frontend" selected>Frontend</option>
<option value="backend">Backend</option>
<option value="mobile" selected>Mobile apps</option>
<option value="ai">Artificial intelligence</option>
</select>size
numberThe number of visible rows in the list. A value greater than 1 turns the dropdown menu into a fixed list box, even without multiple.
<select name="level" size="3" aria-label="Level">
<option>Beginner</option>
<option>Intermediate</option>
<option>Advanced</option>
</select>required
boolean attributeRequires an option with a non-empty value to be selected. A popular pattern is a first option with an empty value, for example "Choose a city…", which acts as a hint and fails validation.
<form>
<select name="city" required aria-label="City">
<option value="">Choose a city…</option>
<option value="chi">Chicago</option>
<option value="aus">Austin</option>
<option value="sea">Seattle</option>
</select>
<button>Next</button>
</form>disabled
boolean attributeDisables the entire list. The value of a disabled list isn’t sent with the form.
<select name="plan" disabled aria-label="Plan">
<option>Yearly plan</option>
</select>Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Always connect the list to a
<label>. A first option like "Choose…" doesn’t replace a label. - The appearance of a dropdown list can only partly be changed in CSS. The new mechanism for full styling (
appearance: base-select) currently only works in some browsers. - For very long lists, such as hundreds of cities, consider a text field with
<datalist>suggestions instead.
Related entries
#- <option>A single option in a `<select>` list, or a suggestion in a `<datalist>`.
- <optgroup>A named group of options inside a `<select>` list.
- <datalist>A list of suggestions for an `<input>` field. You can pick a proposal or type your own value.
- <label>A form field’s label. Clicking the label moves the cursor to the field.
- <form>A form that collects data from the user and sends it to a given address.
Spotted a mistake or missing an example? Write to us.