We can define a group of related options in a drop-down list by using the <optgroup> Tag tag is used to create a group of same category options in a drop-down list. The tag is required when there is a long list of items.
Example:
<!DOCTYPE html> <html> <head> <title> How to define a group of related options in a drop-down list? </title> <style> body { text-align: center; } .gfg { font-size: 40px; font-weight: bold; color: green; } .geeks { font-size: 17px; } </style> </head> <body> <div class="gfg">GeeksforGeeks</div> <div class="geeks"> A computer science portal for geeks </div> <h2> How to define a group of related options in a drop-down list </h2> <select> <optgroup label="Programming Languages"> <option value="C">C</option> <option value="C++">C++</option> <option value="Java">Java </optgroup> <optgroup label="Scripting Language"> <option value="JavaScript">JavaScript</option> <option value="PHP">PHP</option> <option value="Shell">Shell</option> </optgroup> </select> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to clear all options in a dropdown box?
- How to Create a Dropdown List with Array Values using JavaScript ?
- How to get selected value in dropdown list using JavaScript ?
- How to specify a list of pre-defined options for input controls in HTML5?
- HTML | DOM Datalist options Collection
- How to remove the default arrow icon from a dropdown list?
- How to Add Image into Dropdown List for each items ?
- How to fix number of visible items in HTML dropdown and allow multiple selections ?
- How to remove options from select element using jQuery ?
- How to add options to a select element using jQuery?
- How to get N options from the <select> element using JQuery?
- How to style a dropdown using CSS?
- How to display div elements using Dropdown Menu in jQuery?
- How to design full width dropdown Navbar using Bootstrap ?
- How to show/hide dropdown menu on mouse hover using CSS ?
- AngularJS | ng-options Directive
- AngularJS | ng-model-options Directive
- HTTP headers | X-Frame-Options
- HTTP headers | X-Content-Type-Options
- Difference between multiple arguments and options object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


