HTML Select Controls: Options and Option Groups
Choose one option
A select contains option elements. The displayed text helps the user choose; value is the submitted string. If value is absent, the option’s text determines its value. Use selected to establish an explicit default.
<form> <label> Language <select name="lang"> <option value="en">English</option> <option value="fa" selected>Persian</option> </select> </label></form>Persian is displayed as selected and lang=fa is included in form data.
Group related choices
optgroup labels a collection of options. It cannot be selected as a value itself. A disabled group disables its options. Group by meaning rather than by an arbitrary visual separator.
<label> Course <select name="course"> <optgroup label="Web"> <option value="html">HTML</option> <option value="css">CSS</option> </optgroup> <optgroup label="Data" disabled> <option value="sql">SQL</option> </optgroup> </select></label>Web and Data group the options; SQL is unavailable because its group is disabled.
Allow multiple selections
The multiple attribute permits more than one selected option. Each selected, enabled option contributes a separate entry with the same name. A native multi-select may be rendered as a list box.
<form> <label> Topics <select name="topic" multiple size="3"> <option value="html" selected>HTML</option> <option value="css" selected>CSS</option> <option value="js">JavaScript</option> </select> </label></form>Two initial entries share the topic key: html and css.
Common mistakes and practice
selected is a Boolean attribute; selected="false" still marks a default selection. A select without multiple permits one selected option at a time. For a multiple select, provide clear instructions because selection gestures differ by device. Disabled options are not submitted.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Select Controls: Options and Option Groups — Knowledge Check
Apply the form-control concepts from this lesson.
What is submitted for <option value="am">Morning</option>?
Which element labels a group of options?
How does a multiple select submit two selected enabled options?
How do you mark an option initially selected in HTML?
A select must offer related categories in labeled groups. Which structure is appropriate?