The <select> HTML element represents a control that provides a menu of options.
Definition and Usage
The <select> element is used to create a drop-down list.
The <select> element is most often used in a form, to collect user input.
The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted).
The id attribute is needed to associate the drop-down list with a label.
The <option> tags inside the <select> element define the available options in the drop-down list.
Tip: Always add the <label> tag for best accessibility practices!
Browser Support
Attributes
Attribute
Value
Description
autofocus
autofocus
Specifies that the drop-down list should automatically get focus when the page loads
disabled
disabled
Specifies that a drop-down list should be disabled
form
form_id
Defines which form the drop-down list belongs to
multiple
multiple
Specifies that multiple options can be selected at once
name
name
Defines a name for the drop-down list
required
required
Specifies that the user is required to select a value before submitting the form
size
number
Defines the number of visible options in a drop-down list
Global Attributes
The <select> tag also supports the Global Attributes in HTML.
Event Attributes
The <select> tag also supports the Event Attributes in HTML.
The disabled attribute for <select> element in HTML is used to specify that the select element is disabled. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute.
Definition and Usage
The disabled attribute is a boolean attribute.
When present, it specifies that the drop-down list should be disabled.
A disabled drop-down list is unusable and un-clickable.
The disabled attribute can be set to keep a user from using the drop-down list until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript can remove the disabled value, and make the drop-down list usable.
The form attribute specifies the form the drop-down list belongs to.
The value of this attribute must be equal to the id attribute of a <form> element in the same document.
Browser Support
Syntax
<select form="form_id">
Attribute Values
Value
Description
form_id
Specifies the form element the <select> element belongs to. The value of this attribute must be equal to the id attribute of a <form> element in the same document.
How to create HTML <select> form Attribute
It is A drop-down list located outside a form (but still a part of the form)
index.html
Output should be:
What is HTML <select> multiple Attribute
Definition and Usage
The multiple attribute is a boolean attribute.
When present, it specifies that multiple options can be selected at once.
Selecting multiple options vary in different operating systems and browsers:
For windows: Hold down the control (ctrl) button to select multiple options
For Mac: Hold down the command button to select multiple options
Because of the different ways of doing this, and because you have to inform the user that multiple selection is available, it is more user-friendly to use checkboxes instead.
Browser Support
Syntax
<select multiple>
How to add HTML <select> multiple Attribute
It is A drop-down list that allows multiple selections.
The size attribute specifies the number of visible options in a drop-down list.
If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.
Browser Support
Note: In Chrome and Safari, this attribute may not work as expected for size="2" and size="3".
Syntax
<select size="number">
Attribute Values
Value
Description
number
The number of visible options in the drop-down list. Default value is 1. If the multiple attribute is present, the default value is 4