HTML Select
When the answer must be one of several known choices, a select dropdown (or list) is clearer than free typing.
Direct answer
Wrap <option> elements in <select name="…">. The selected option’s value is what gets submitted. Label the control. Use <optgroup label="…"> to group options when the list is long.
Basic select
html<label for="city">City</label>
<select id="city" name="city">
<option value="">Choose…</option>
<option value="teh">Tehran</option>
<option value="isf">Isfahan</option>
</select>
Options with optgroup
html<label for="meal">Meal</label>
<select id="meal" name="meal">
<optgroup label="Veg">
<option value="salad">Salad</option>
<option value="soup">Soup</option>
</optgroup>
<optgroup label="Other">
<option value="stew">Stew</option>
</optgroup>
</select>
Try it
- Create a labeled select with three city options
- Include an empty “Choose…” option first
- Add an optgroup version for practice
- Confirm
nameandvalueare set
Easy mistakes
- Forgetting
valueso the visible text is submitted unintentionally (sometimes OK, often not what you meant) - No label on the select
- Huge ungrouped lists that are hard to scan
Summary
select+optionbuild choice listsnameon select;valueon optionsoptgrouporganizes long lists- Always label the control
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top