Adding Attributes to Select Element
We can add attributes to the Select element to make it more interactive for users. Here are some of the important attributes of HTML Select Element.
A: Size Attribute
size
attribute specifies how many options must be visible at a time. Here's an example:
<select size="3">
<!-- three options visible by default -->
<option value="Amsterdam">Amsterdam</option>
<option value="Berlin">Berlin</option>
<option value="Paris">Paris</option>
<option value="Barcelona">Barcelona</option>
<option value="Madrid">Madrid</option>
</select>
B: Name Attribute
Name
attribute assigns a name to the select element. Here's an example:
<select name="city">
<option value="Amsterdam">Amsterdam</option>
<option value="Berlin">Berlin</option>
<option value="Paris">Paris</option>
<option value="Barcelona">Barcelona</option>
<option value="Madrid">Madrid</option>
</select>
C: Multiple Attribute
multiple
attribute allows users to select more than one option at the same time. Here's an example:
<select multiple>
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
</select>