Problem Statement
Which tag is used to create a dropdown list?
Explanation
The select tag is used to create a dropdown list in HTML forms. A dropdown list presents options in a compact menu that expands when clicked. The select tag contains multiple option tags, each representing one choice. The user can select one option from the dropdown by default, or multiple options if you add the multiple attribute. Dropdowns are ideal when you have many options that would take too much space as radio buttons, such as countries, states, or years. The selected option's value is sent to the server using the select's name attribute. You can also use optgroup tags to organize options into categories. Dropdowns save screen space and work well on mobile devices. They are better than radio buttons when you have more than seven options.
Code Solution
SolutionRead Only
<!-- Basic dropdown -->
<form>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="">Select a country</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
<option value="au">Australia</option>
</select>
</form>
<!-- Dropdown with default selection -->
<form>
<label for="month">Birth Month:</label>
<select id="month" name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4" selected>April</option>
<option value="5">May</option>
</select>
</form>
<!-- Multiple selection dropdown -->
<form>
<label for="languages">Programming Languages:</label>
<select id="languages" name="languages" multiple size="4">
<option value="python">Python</option>
<option value="javascript">JavaScript</option>
<option value="java">Java</option>
<option value="cpp">C++</option>
</select>
</form>