HTML select tag
HTML

HTML select tag

Mishel Shaji
Mishel Shaji

The HTML select tag is used to create a drop-down list. Each item in the list is defined using the <option> tag.

Attributes

AttributeDefinition
autofocusThis Boolean attribute is used to specify whether form control should have input focus when the page loads.
disabledThis Boolean attribute indicates whether the element is disabled. If disabled, the user cannot interact with the element.
formSpecifies one or more forms the field belongs to.
multipleThis Boolean attribute indicates that multiple options can be selected in the list. If not specified, only one option can be selected.
nameSpecifies the name of the element.
requiredSpecifies that the user should select a value for submitting the form.
sizeSpecifies 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>