HTML - <select> tag in HTML

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:

  1. name
    Specifies the name of the drop-down list, used when sending form data.
    Example: <select name="country">

  2. id
    Specifies a unique identifier for the element, often used with CSS or JavaScript.
    Example: <select id="city">

  3. multiple
    Allows the user to select more than one option.
    Example: <select multiple>

  4. size
    Defines the number of visible options. If size is more than 1, the list appears as a box.
    Example: <select size="4">

  5. disabled
    Disables the drop-down list so the user cannot interact with it.
    Example: <select disabled>

  6. 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>