Forms & Controls

HTML <select> element

Build a form with the HTML form generator

Provides a selection control with option children, optionally grouped with optgroup. multiple allows selecting more than one value. Use a label and meaningful option values. A single-select normally chooses one option; multiple permits multiple selections. Traditional and customizable select markup differ and the latter needs compatibility testing. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<select name="choice">  <option value="a">A</option></select>

Parameters & Attributes

NameTypeDescription
autocompleteordered autofill tokens or on/offGives the browser the purpose of a form field or controls autofill. Use meaningful tokens such as email or current-password. A browser may still offer password-manager autofill even with off.
disabledbooleanDisables supported controls or elements. Disabled form controls are generally not focusable, validated or submitted. The exact effect depends on the element; disabled="false" still disables.
formform element IDAssociates an eligible control with a form elsewhere in the same document, overriding an ancestor form where applicable. Does not automatically associate descendants of a fieldset.
multiplebooleanAllows multiple files, comma-separated email addresses or multiple select options depending on the element. It does not apply to ordinary text inputs.
namestringProvides an element-specific name: a form field key, radio group name, named frame, metadata key, slot name or other defined purpose. Its meaning depends on the element; it is not a unique DOM identifier.
requiredbooleanMakes supported form controls subject to a nonempty or selected-value constraint. Radio-group and checkbox behavior differs. It does not perform server-side validation.
sizepositive integerVisible option count, not a maximum number of selected items.

Return Value

HTMLSelectElement

Content model: Traditional controls use option, optgroup and optional hr; customizable select allows additional specified markup.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <title>HTML example</title>  </head>  <body>    <label>      Format      <select name="format">        <option>Paperback</option>        <option>E-book</option>      </select>    </label>  </body></html>
HTML Reference