Table of contents
- 1. Summary
- 2. Usage content
- 3. Attributes
- 4. DOM Interface
- 5. Examples
- 5.1.1. Result
- 5.2. Compatibility
- 6. See also
Summary
The select (<select>) HTML element represents a control that presents menu of options. The options within the menu are represented by <option>
elements, which can be grouped by <optgroup>
elements. Options can be pre-selected for the user.
Usage content
| Content categories | flow content, phrasing content, interactive content, listed, labelable, resettable, and submittable form-associated element |
| Permitted content | Zero or more <option>
or <optgroup>
elements. |
| Tag omission | none, both the start tag and the end tag are mandatory |
| Permitted parent elements | any element that accepts phrasing content |
| Normative document | HTML5, section 4.10.9 (HTML4.01, section 17.6) |
Attributes
Like all other HTML elements, this element supports the global attributes.
-
autofocusHTML5 - This attribute lets you specify that a form control should have input focus when the page loads, unless the user overrides it, for example by typing in a different control. Only one form element in a document can have the
autofocusattribute, which is a Boolean. -
disabled - This Boolean attribute indicates that the user cannot interact with the control. If this attribute is not specified, the control inherits its setting from the containing element, for example
fieldset; if there is no containing element with thedisabledattribute set, then the control is enabled. -
formHTML5 - The form element that the select element is associated with (its "form owner"). The value of the attribute must be an ID of a form element in the same document. If this attribute is not specified, the select element must be a descendant of a form element. This attribute enables you to place select elements anywhere within a document, not just as descendants of their form elements.
-
multiple - This Boolean attribute indicates that multiple options can be selected in the list. If it is not specified, then only one option can be selected at a time.
-
selectedIndex - The index of the selected
<option>element. -
name - The name of the control.
-
requiredHTML5 - A Boolean attribute indicating that an option with a non-empty string value must be selected.
-
size - If the control is presented as a scrolled list box, this attribute represents the number of rows in the list that should be visible at one time. Browsers are not required to present a select elements as a scrolled list box. The default value is 0.
Note: According to the HTML5 specification, the default value for size should be 1; however, in practice, this has been found to break some web sites, and no other browser currently does that, so we have opted to continue to return 0 for the time being.
DOM Interface
This element implements the HTMLSelectElement interface.
Examples
<!-- The second value will be selected initially --> <select name="select"> <option value="value1">Value 1</option> <option value="value2" selected>Value 2</option> <option value="value3">Value 3</option> </select>
Result
Compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7 or earlier) | (Yes) | (Yes) | (Yes) |
required attribute | (Yes) | 4.0 (2.0) | -- | (Yes) | (Yes) |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | (Yes) | 1.0 (1.0) | (Yes) | (Yes) | (Yes) |
required attribute | (Yes) | 4.0 (2.0) | -- | (Yes) | (Yes) |
See also
- Other form-related elements:
<form>,<legend>,<label>,<button>,<option>,<datalist>,<optgroup>,<fieldset>,<textarea>,<keygen>,<input>,<output>,<progress>and<meter>.
Mozilla Developer Network