In HTML, the <select>
element is used to display a menu or drop-down list.
<select name="" id="" autofocus disabled form="" multiple required size="">menu content</select>
Where:
name
: Specifies the name of the drop-down list. name
is needed to reference the form data after the form is submitted.id
: Specifies the ID of the drop-down list. id
is needed to associate the drop-down list with a label.autofocus
: Takes boolean as a value. autofocus
specifies that a form control should have input focus when the page loads and can only be assigned to one form element.disabled
: A boolean attribute specifying if an option is disabled or not. If disabled
is set, then the option is not selectable. This makes browsers unable to receive any events like mouse clicks or focus-related.form
: Specifies which form the drop-down list is associated with.multiple
: Takes a boolean attribute specifying that multiple options can be selected from the menu.required
: Takes a boolean attribute specifying that an option with a non-empty string value must be selected before submitting the form.size
: Takes a number as a value and specifies the number of visible items in the drop-down list.The following code demonstrates the usage of the <select>
element in HTML.
The content that we want to display as a drop-down menu is written within the opening and closing tags, <select>
and </select>
.