A required select with optgroup and a disabled option
<select name required>
<option value="" selected disabled>
<optgroup label>
<option value>
</optgroup>
</select>A placeholder option with an empty value keeps a required single-selection select incomplete until a real option is chosen.
| Attribute | Description |
|---|---|
name | The field name used in form submission. Without name, the control is not submitted. |
required | A boolean. For a single-selection select, the control is incomplete while the selected option has an empty value. This page does not run constraint validation. |
value (option) | The option's submitted value. If omitted, the value is the option's text content. |
selected (option) | Marks the default selected option. In a single-selection select, at most one option should be selected in the markup. |
disabled (option) | The option cannot be chosen and is not a successful control. A disabled placeholder can still be the initial selected option. |
label (optgroup) | The visible group heading. A disabled optgroup disables the options it contains. |
- There is no remote form action. The fragment is not submitted, and no user-agent picker UI was opened.
<form>
<label for="region">Region</label>
<select id="region" name="region" required>
<option value="" selected disabled>Choose a region</option>
<optgroup label="Americas">
<option value="us">United States</option>
<option value="ca">Canada</option>
</optgroup>
<optgroup label="Europe">
<option value="de">Germany</option>
<option value="fr" disabled>France (unavailable)</option>
</optgroup>
</select>
<button type="submit">Save region</button>
</form>What this markup means
The placeholder option has an empty value, is selected, and is disabled so it is only a prompt. Choosing United States would submit region=us if this form were submitted. The France option is disabled in the tree, so it is not a successful value. Nothing is submitted from this page.
Related: Tag catalog: <select>, <form>, <label>, <input>