HTML <select> Tag using <optgroup>
The HTML <optgroup> tag is used for grouping related options within a <select> element. If we have a big list of options,then we can make groups of related options which are easy to be handled by the user.
Code of <select> tag using <optgroup>
<html>
<head>
<title>Adding Select Control With Optgroup</title>
</head>
<body>
<h1>Adding Select Control With Optgroup</h1>
<select>
<optgroup label="Languages" style="background-color: teal;">
<option value="c">C Language</option>
<option value="cpp">C++</option>
<option value="python">Python</option>
</optgroup>
<optgroup label="Front End" style="background-color: yellowgreen;">
<option>HTML</option>
<option>CSS</option>
<option>Java Script</option>
</optgroup>
<optgroup label="Back End" style="background-color: cornflowerblue;">
<option>Java</option>
<option>Python</option>
<option>PHP</option>
</optgroup>
</select>
</body>
</html>
<head>
<title>Adding Select Control With Optgroup</title>
</head>
<body>
<h1>Adding Select Control With Optgroup</h1>
<select>
<optgroup label="Languages" style="background-color: teal;">
<option value="c">C Language</option>
<option value="cpp">C++</option>
<option value="python">Python</option>
</optgroup>
<optgroup label="Front End" style="background-color: yellowgreen;">
<option>HTML</option>
<option>CSS</option>
<option>Java Script</option>
</optgroup>
<optgroup label="Back End" style="background-color: cornflowerblue;">
<option>Java</option>
<option>Python</option>
<option>PHP</option>
</optgroup>
</select>
</body>
</html>
Output:

