- 1HTML Forms
- 2HTML form Tag
- 3HTML Input Types
- 4HTML Labels and Placeholders
- 5HTML Select Dropdown
- 6HTML Checkbox
- 7HTML Radio Buttons
- 8HTML Textarea
- 9HTML Submit and Reset Buttons
- 10HTML Form Validation
- 11HTML Required Fields
- 12HTML Input Pattern Attribute
- 13HTML min and max Attribute
- 14HTML Form Action and Method
- 15HTML Fieldset and Legend
- 16HTML Form Advanced Controls
- 17HTML Date Picker
- 18HTML Range Slider
- 19HTML Color Picker
- 20HTML File Upload
- 21HTML Datalist
- 22HTML Autofocus and Autocomplete
HTML <select> Tag
select and option Elements
HTML <select> Tag: Building Dropdown Menus
Sometimes, users don’t need to type — they just need to choose. The <select>
tag creates a dropdown menu where users can pick from predefined options. It's perfect for countries, categories, ratings, and yes — even favorite fruits.
Basic Structure of a Select Element
The <select>
element wraps around one or more <option>
tags. Each <option>
represents a possible choice.
<label for="fruit">Choose a fruit:</label>
<select id="fruit" name="fruit">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select>
Choose a fruit: [ Apple ▼ ]
When submitted, the selected value (like "banana") will be passed as part of the form data.
Setting a Default Selection
You can preselect a value using the selected
attribute.
<select name="fruit">
<option value="apple">Apple</option>
<option value="banana" selected>Banana</option>
<option value="cherry">Cherry</option>
</select>
[ Banana ▼ ]
This improves usability when one option is the most common or recommended.
Adding a Placeholder Option
If you want to nudge users to make a choice, use a disabled, selected first option:
<select name="fruit">
<option disabled selected>-- Select a fruit -->
<option>Apple</option>
<option>Banana</option>
<option>Cherry</option>
</select>
[ -- Select a fruit -- ▼ ]
This option can’t be selected on submit — it's just a friendly guide.
Creating a Multi-Select List
Add the multiple
attribute to allow more than one selection. You’ll also want to adjust the size
to show more than one line.
<label for="fruits">Select multiple fruits:</label>
<select id="fruits" name="fruits" multiple size="3">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select>
Apple
Banana
Cherry
(hold Ctrl/Command to select multiple)
Form submission will include all selected values under the fruits
name.
Grouping Options with <optgroup>
If you have related sets of options, use <optgroup>
to visually separate them.
<select name="food">
<optgroup label="Fruits">
<option>Apple</option>
<option>Banana</option>
</optgroup>
<optgroup label="Vegetables">
<option>Carrot</option>
<option>Spinach</option>
</optgroup>
</select>
[ Fruits ▸ ]
Apple
Banana
[ Vegetables ▸ ]
Carrot
Spinach
This adds semantic structure and clarity, especially for longer lists.
Best Practices
- Use
label
withfor
to describe the dropdown - Always define
value
in each option — it's what gets submitted - Group logically using
<optgroup>
when necessary - Set default or placeholder options to guide user interaction
Full Example: Fruit Selection Form
<form action="/submit" method="post">
<label for="fruit">Choose your favorite fruit:</label><br>
<select id="fruit" name="fruit">
<option disabled selected>-- Select one -->
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="cherry">Cherry</option>
</select><br><br>
<input type="submit" value="Submit">
</form>
Choose your favorite fruit:
[ -- Select one -- ▼ ]
[Submit]
Summary
The <select>
tag creates clean, structured dropdowns that simplify user choice. You’ve learned to:
- Create single and multi-select dropdown menus
- Set default selections and placeholders
- Group options meaningfully
What’s Next?
Up next, we’ll cover Checkboxes and Radio Buttons — essential tools for collecting user preferences and single/multi-choice answers.
QUIZ
Question 1:Which HTML tag is used to create a dropdown menu?
Question 2:The <option>
tag must always be used inside a <select>
tag.
Question 3:Which of the following attributes can be used with the <select>
tag?
Question 4:What is the output of the following code?
<select name="class">
<option>10th</option>
<option>11th</option>
<option>12th</option>
</select>
<select name="class">
<option>10th</option>
<option>11th</option>
<option>12th</option>
</select>