HTML - <optgroup> Tag


Advertisements


Description

The HTML <optgroup> tag is used for grouping related options within your select list. This makes it easier for users to comprehend their choices when looking at a large list.

Example

<!DOCTYPE html>
<html>

   <head>
      <title>HTML optgroup Tag</title>
   </head>

   <body>
      <select>
         <optgroup label = "India">
            <option value = "mumbai">Mumbai</option>
            <option value = "delhi">Delhi</option>
         </optgroup>
         
         <optgroup label = "USA">
            <option value = "florida">Florida</option>
            <option value = "newyork">New York</option>
         </optgroup>
      </select>
   </body>
   
</html>

This will produce the following result −

Global Attributes

This tag supports all the global attributes described in − HTML Attribute Reference

Specific Attributes

The HTML <optgroup> tag also supports the following additional attributes −

Attribute Value Description
disabled disabled Disables the input control. The button won't accept changes from the user. It also cannot receive focus and will be skipped when tabbing.
label text Defines a label to use when using <optgroup>.

Event Attributes

This tag supports all the event attributes described in − HTML Events Reference

Browser Support

Chrome Firefox IE Opera Safari Android
Yes Yes Yes Yes Yes Yes

html_tags_reference.htm

Advertisements