![]() |
The Definition and UsageThe If you have a long list of options, groups of related options are easier to handle for a user. Browser SupportAttributes
Global AttributesThe Event AttributesThe |
Example:
HTML
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
The disabled attribute for <optgroup> element in HTML is used to specify that the option-group is disabled. A disabled optgroup is un-clickable and unusable. It is a boolean attribute.
The disabled
attribute is a boolean attribute.
When present, it specifies that an option-group should be disabled.
A disabled option-group is unusable and un-clickable.
The disabled
attribute can be set to keep a user from selecting the option-group until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript is required to remove the disabled value, and make the option-group selectable.
The numbers in the table specify the first browser version that fully supports the attribute.
<optgroup disabled>
A disabled option-group.
The optgroup disabled attribute
Example:
HTML
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars" disabled>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
The label
attribute specifies a label for an option-group.
<optgroup label="text">
Value | Description |
---|---|
text | Specifies a label/description for the option-group |
Two option-groups with labels.
Example:
HTML
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select name="cars" id="cars">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
html optgroup |
How to create HTML <optgroup> Tag | HTML Tag |
What is HTML <optgroup> disabled Attribute | HTML Tag |
How to add HTML <optgroup> disabled Attribute | HTML Tag |
What is HTML <optgroup> label Attribute | HTML Tag |
How to add HTML <optgroup> label Attribute | HTML Tag |
Read Full: | HTML Tag |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Tag |
Uploaded: | 6 months ago |
Uploaded by: | Admin |
Views: | 189 |
Reffered: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup