HTML dropdown list - how to use <select> tag

The HTML <select> tag is used to define a dropdown list.

Attributes

The select tag supports the global and event attributes.

autofocus
Defines that the dropdown list should automatically get focus when the page loads
disabled
Defines the dropdown list be disabled
form
Defines ome or more form ids that this select tag belongs to
multiple
Defines that multiple options can be selected
name
Defines the name of the dropdown list
required
Defines that the dropdown list is required for submitting the form
size
Defines the number of visible items for the dropdown list

Examples:

<select> <optgroup label="American cities"> <option value="New York">New York</option> <option value="Washington">Washington</option> </optgroup> <optgroup label="Chinese cities"> <option value="Beijing">Beijing</option> <option value="Shanghai">Shanghai</option> </optgroup> <optgroup label="Australian cities"> <option value="Sydney">Sydney</option> <option value="Melbourne">Melbourne</option> </optgroup> </select>

Related HTML tags and useful links: