The <select> tag in HTML is used to create a drop-down list. It allows users to choose one (or multiple) options from a list of items.
Attributes of the <select> tag:
-
name
Specifies the name of the drop-down list, used when sending form data.
Example: <select name="country">
-
id
Specifies a unique identifier for the element, often used with CSS or JavaScript.
Example: <select id="city">
-
multiple
Allows the user to select more than one option.
Example: <select multiple>
-
size
Defines the number of visible options. If size is more than 1, the list appears as a box.
Example: <select size="4">
-
disabled
Disables the drop-down list so the user cannot interact with it.
Example: <select disabled>
-
autofocus
Automatically focuses on the drop-down when the page loads.
Example: <select autofocus>
The <option> tag is used inside <select> to define each available choice. Example:
<select name="fruit">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
</select>