Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Forms

The <select> element

Reference for the HTML <select> element: drop-downs and list boxes, multiple and size, placeholder options, required, grouping with optgroup, accessibility and technical details.

The <select> element lets the user choose from a fixed list of options. By default it is a drop-down that shows one choice at a time. With multiple or a size greater than 1 it becomes a list box that shows several rows. Each choice is an <option>, and options can be grouped with <optgroup>.

HTML
<label for="size">T-shirt size</label>
<select id="size" name="size">
  <option value="s">Small</option>
  <option value="m" selected>Medium</option>
  <option value="l">Large</option>
</select>

The submitted pair is the name plus the chosen option's value, for example size=m.

Try it

Drop-down and multi-select

The empty-value first option works as a placeholder: with required, the form can't be submitted while it is selected. A multiple select sends one pair per selected option.

Attributes

Attribute Values Description
name Text Name submitted with the selected value(s).
multiple Boolean Allows more than one option to be selected and shows a list box.
size Positive integer Number of visible rows. Default 1 for a drop-down, 4 with multiple.
required Boolean A non-empty choice is needed before the form can be submitted.
disabled Boolean The control can't be used and is not submitted.
form ID of a <form> Associates the select with a form elsewhere in the document.
autocomplete on, off or an autofill token such as country, bday-month Helps the browser autofill the choice.

It also accepts the global attributes, such as autofocus.

Usage notes

  • Use a select when the list is fixed and has roughly 5 to 15 options. For two to four options, radio buttons show every choice at once. For very long lists, consider <input> with a <datalist> so users can type.
  • Placeholders need an empty value. required only treats the first option as "no choice" when its value is empty and it isn't inside an <optgroup>.
  • Value fallback. If an option has no value, its text is submitted.
  • Multi-selects are hard to use. Ctrl/โŒ˜-clicking is unfamiliar to many people and awkward on touch screens. A group of checkboxes is usually friendlier.
  • Always label it. A select without a <label> is announced only by its current value.
  • Don't navigate on change. Submitting or redirecting as soon as the value changes surprises keyboard users, who change the value with arrow keys. Add a button instead.
  • Styling. The closed control can be styled with CSS; the open list is drawn by the operating system. Newer browsers support a customizable select (appearance: base-select) that lets you style the button and the options, but support is still limited.

Technical summary

Content categories Flow content, phrasing content, interactive content, palpable content; form-associated: listed, labelable, submittable, resettable
Permitted content Zero or more <option>, <optgroup>, <hr> and script-supporting elements (customizable select allows some additional content)
Tag omission None; both the start and end tags are required
Permitted parents Any element that accepts phrasing content
Implicit ARIA role combobox without multiple and with no size greater than 1; otherwise listbox
DOM interface HTMLSelectElement
Default display inline-block

Browser support

Supported in every browser. The customizable select (appearance: base-select) is a recent feature that is not yet available in all browsers; the classic select works everywhere.