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 >
|
Output:

Supported Browsers are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!