The HTML select tag is used to create a drop-down list. Each item in the list is defined using the <option> tag.
Attributes
Attribute | Definition |
autofocus | This Boolean attribute is used to specify whether form control should have input focus when the page loads. |
disabled | This Boolean attribute indicates whether the element is disabled. If disabled, the user cannot interact with the element. |
form | Specifies one or more forms the field belongs to. |
multiple | This Boolean attribute indicates that multiple options can be selected in the list. If not specified, only one option can be selected. |
name | Specifies the name of the element. |
required | Specifies that the user should select a value for submitting the form. |
size | Specifies the number of items shown in the list. |
Example – a simple select tag
<select>
<option value="keyboard">Keyboard</option>
<option value="mouse">Mouse</option>
<option value="printer">Printer</option>
<option value="scanner">Scanner</option>
<option value="webcam">Web cam</option>
</select>
Output
Example – select tag with size and multiple attributes
<select size="2" multiple>
<option value="keyboard">Keyboard</option>
<option value="mouse">Mouse</option>
<option value="printer">Printer</option>
<option value="scanner">Scanner</option>
<option value="webcam">Web cam</option>
</select>
Output
Press and hold Ctrl to select multiple options.
Note: According to the HTML5 specification, the default value for size should be 1.
Example – required attribute
<form action="/actionpage.php">
<select required>
<option value="">Select an option</option>
<option value="keyboard">Keyboard</option>
<option value="mouse">Mouse</option>
<option value="printer">Printer</option>
<option value="scanner">Scanner</option>
<option value="webcam">Web cam</option>
</select>
<input type="submit">
</form>
Subscribe
Join the newsletter to get the latest updates.