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.
The following are the 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>. |
Example
You can try to run the following code to create an option group in HTML −
<!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>