<optgroup> Tag Syntax
Rules for coding HTML optgroup
elements
<body> ... flow content expected ... <form method="POST" action="form-handler"> ... flow content ... <select> ... <optgroup label="..."> <option>...</option> ... </optgroup> ... </select> ... flow content ... </form> ... </body>
Rules for coding the HTML optgroup element
Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.
- Inside a select element, include an optgroup element for each group of options in the select list.
- Begin the optgroup element with a starting <optgroup> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the
xmlns
attribute on the <html> tag. - Inside the <optgroup> starting tag, include a label attribute with the label for the option group.
- Inside the optgroup element, between the starting
<optgroup>
tag and the ending</optgroup>
tag, code the options of the select list. - End the optgroup element with a matching
</optgroup>
closing tag.
optgroup Content Model
Content of the optgroup element
The content of the optgroup element consists of a list of options, each created with an <option> tag.