<optgroup> : Option Group element

Introduction

In HTML, the <optgroup> element is used to group related options within a <select> dropdown list. It does not represent a selectable option itself but rather acts as a container for grouping options together.

Here’s an example of how it’s used:

Output :

In this example, there are two <optgroup> elements: one for grouping fruits and another for grouping vegetables. Each <optgroup> contains a set of <option> elements that belong to that group.

When rendered in a browser, the options within each <optgroup> will typically be visually grouped together, making it easier for users to identify related choices within the dropdown menu.

Leave a Comment