HTML Tag Reference - HTML tag <optgroup>








This <optgroup> element groups multiple options within a <select> element list together. The option groups cannot be nested within other option groups.

Browser compatibility

<optgroup> Yes Yes Yes Yes Yes

What's new in HTML5

None.

Attribute

Attribute Value Description
disabled disabled diable an option-group
label text Set a label for an option-group




Global Attributes

The <optgroup> tag supports the Global Attributes in HTML.

Event Attributes

The <optgroup> tag supports the Event Attributes in HTML.

Default CSS Settings

None.

Example

A demo showing how to use <optgroup> tag.

<html>
<body>
     <form>
        <select name="select1">
           <optgroup label="First Group">
                <option>First</option>
                <option>second</option>
                <option>third</option>
           </optgroup>
           <optgroup label="Second Group">
                <option>First item in second group</option>
                <option>Second item in second group</option>
                <option>Third item in second group</option>
           </optgroup>
        </select>
     </form>
</body><!--  w w w.j av a2 s. co  m-->
</html>

Click to view the demo