HTML select tag

What Is the HTML Select Element?

You can create drop-down list by user select tag. The <select> element is defined using an opening <select> tag and a closing </select> tag, with the available options placed between them. You can create individual list items with <option></option> tags. The example of select field is mentioned below: Example


<select name="myColor" id="myColoe">
  <option value="Green"> Green</option>
  <option value="Blue"> Blue</option>
  <option value="Red"> Red</option>
  <option value="Yellow"> Yellow</option>
  <option value="Black"> Black</option>
  <option value="White"> White</option>
</select>
Output


In above mentioned example you can select only one option at a time. And there will be only one option will be visible at your screen. If you want to display more than one list items so you can set size attribute of the select tag. Example is mentioned below: Example

<select name="myColor" id="myColoe" size="3">
  <option value="Green"> Green</option>
  <option value="Blue"> Blue</option>
  <option value="Red"> Red</option>
  <option value="Yellow"> Yellow</option>
  <option value="Black"> Black</option>
  <option value="White"> White</option>
</select>
Output


By default, a dropdown list allows users to select only one option at a time. To let users select multiple options, add the multiple attribute to the <select> tag. You can also use the size attribute to specify how many options are visible at once. Example is mentioned below: Example

<select name="myColor" id="myColoe" size="3" multiple>
  <option value="Green"> Green</option>
  <option value="Blue"> Blue</option>
  <option value="Red"> Red</option>
  <option value="Yellow"> Yellow</option>
  <option value="Black"> Black</option>
  <option value="White"> White</option>
</select>
Output


Attribute Description
Id Through id attribute you can identify the select field in your HTML file. Multiple select field in an HTML file can be possible so in this condition you can easily identify select field through their ids.

id="any"
Name Through name attribute you can identify the select field in your HTML file. Multiple select field in an HTML file can be possible so in this condition you can easily identify select field through their names.

name="any"
Size If you want to display more than one list items so you can set size attribute of the select tag.
multiple If you want to create a list in which you can select multiple list items so you will have to add "Multiple" attribute in the select tag.
Selected If you want to select any list option at your default option so you can add selected attribute in your <option></option> tag. Example is mentioned below:

<select name="myColor" id="myColoe" size = 3 multiple>
  <option> Green</option>
  <option> Blue</option>
  <option selected> Red</option>
</select>	
In above mentioned example red will be selected at the time of page load by default.

FAQ 1. Can I Customize an HTML Select Element Using CSS? Yes, CSS can be used to customize the appearance of a dropdown list. You can change its width, height, background color, border, font size, padding, and other visual properties to match your website design. 2. What Is the Purpose of the Size Attribute in an HTML Select Element? The size attribute specifies how many options are visible in the selection list without opening the dropdown. It is useful when you want to display several choices directly on the webpage. 3. What Is the Difference Between a Single-Select and Multiple-Select Dropdown? A single-select dropdown allows users to choose only one option at a time. A multiple-select dropdown allows users to select several options from the same list by using the multiple attribute.