Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<select>

A drop-down list of options.

Syntax

<select name="size">
  <option value="s">Small</option>
</select>

Attributes

ParameterTypeDescription
nametextThe name sent to the server.
multiple—Optional. Allow choosing several items.
sizenumberOptional. How many rows to show as a list.

Examples

Choosing a size:

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

A multi-select list (Ctrl + click):

<select name="toppings" multiple size="3">
  <option>Cinnamon</option>
  <option>Caramel</option>
  <option>Vanilla</option>
</select>

Notes

A drop-down works well with more than five options. With two or three, radio buttons are handier: all options are visible at once. To force a choice, add an empty first <option value=""> and the required attribute.

See also

  • <option>, <optgroup> — An item of a `<select>` or `<datalist>`; `<optgroup>` puts items into groups.
  • <datalist> — A list of suggestions for a text field: pick an option or type your own.
  • <label> — A label for a form field.

Related recipes

In the tutorial

Thanks for reading!

Donate to the site — we work hard for you.