Skip to main content

What does <select> do?

The <select> element creates a dropdown list (a selection menu) in an HTML form. It is used when the user needs to pick one or several options from a predefined set.


1. Basic example

html
<form action="/submit"> <label for="city">Choose a city:</label> <select id="city" name="city"> <option value="kyiv">Kyiv</option> <option value="lviv">Lviv</option> <option value="warsaw">Warsaw</option> </select> <button type="submit">Submit</button> </form>

What happens here:

  • <select> is the container for the list of options,
  • <option> is a single choice,
  • on form submission, the value attribute of the chosen option is sent.

Submission example:

javascript
city=lviv

2. Main tags and attributes

Use it if:

  • the user must pick one option from a list (for example, a city, country or category);
  • the number of options is limited and known in advance;
  • you need a compact UI element that saves space.

Do not use <select> if there are dozens or hundreds of options (autocomplete / search fits better).


Summary:

PropertyDescription
Tag<select>
Nested tags<option>, <optgroup>
PurposeDropdown list for choosing one or several values
Sending dataVia the name attribute and the chosen value
Commonly used attributesmultiple, required, disabled, size, selected

In simple terms: <select> is a dropdown menu where the user chooses an option from a list. If <input> is "entry", then <select> is "choice".

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.