Description
The HTML element <select>
is used to define a selection list, which displays as a pull-down menu from which users can select one or more options.
Each option is defined using the <option>
element.
The select element must contain at least one <option>
element.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as an Inline element. |
Contents | It can contain one or more <option> elements. |
Tags | Both the opening and closing tags are required. |
Versions | HTML 2, 3.2, 4, 4.01, 5 |
Syntax
Here is the basic syntax of the <select>
element.
<select>...</select>
Examples
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example - HTML Element select</title>
</head>
<body>
<form>
<select>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="papaya">Papaya</option>
</select>
</form>
</body>
</html>
Attributes
The following table shows the list of supported and unsupported attributes for the <select>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <select> has some element-specific attributes listed in the below table. |
Global Attributes | Like all other HTML tags, the tag <select> supports the HTML Global Attributes. |
Event Attributes | The tag <select> also supports the HTML Event Attributes. |
Here is a list of attributes that are specific to the <select>
element.
Attribute | Value | Required | Description |
autofocus |
autofocus |
No | Specifies that the drop-down list should automatically get focused when the document is loaded. |
disabled |
disabled |
No | This Boolean attribute indicates that the drop-down list is disabled i.e. the drop-down list is not selectable. |
form |
form-id |
No | Specifies the form that the select element is associated with i.e. its "form owner". |
multiple |
multiple |
No | This Boolean attribute indicates that multiple options can be selected in the list. |
name |
unique-name | No | Defines the name for the select element. |
required |
required |
No | This Boolean attribute indicates that an option with a non-empty value must be selected before form submission. |
size |
number | No | Specifies the number of options to show to the user. |
Browser Compatibility
The tag <select>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 4+