Summary -

In this topic, we described about the <optgroup> tag along with detailed example.

Selection form control option group in HTML documents. The <optgroup> tag used to specify Selection form control option group. <optgroup> used to group the related options together in drop-down list.

This will be useful to handle the related options easy, if list of option are more. The tag can be specified like <optgroup></optgroup> with the related items in between the opening and closing tags.

Closing tag is not needed in case if another <optgroup> element immediately coded and other cases, closing tag is needed.

Syntax -

<optgroup>….</optgroup>

Example -

<!DOCTYPE html>
<html>
<head>
	<title>Optgroup tag example.. </title>
</head>
<body>
	Select from list:
	<select>
		<optgroup label="India">
			<option value=" Andhra pradesh ">Andhra pradesh</option>
			<option value=" Telangana">Telangana</option>
		</optgroup>
		<optgroup label="US">
			<option value=" California">California</option>
			<option value="new jersy">New jersy</option>
		</optgroup>
	</select>
</body>
</html>

Output -

Select from list -