<optgroup> Tag in HTML

The <optgroup> tag in HTML is used to group related options inside a <select> dropdown list. It helps organize large lists of options, making it easier for users to navigate through them.

Key Points on <optgroup> Tag:

Syntax of <optgroup> Tag:

Syntax Example

<optgroup label="Group Name">
            <option value="value1">Option 1</option>
            <option value="value2">Option 2</option>
        </optgroup>

Example of <optgroup> Tag in HTML:

This example demonstrates how to group options in a dropdown list using the <optgroup> tag.

Code Example


        <select>
            <optgroup label="Fruits">
                <option value="apple">Apple</option>
                <option value="banana">Banana</option>
                <option value="orange">Orange</option>
            </optgroup>
        
            <optgroup label="Vegetables">
                <option value="carrot">Carrot</option>
                <option value="broccoli">Broccoli</option>
                <option value="spinach">Spinach</option>
            </optgroup>
        </select>
                

Output

The <optgroup> tag is a powerful way to group related options inside a <select> dropdown, improving the user experience by organizing long lists of choices into categories.