Items in levels within an HTML ComboBox. It's possible?

2

Let's say you want to list in a ComboBox items for sale on an e-commerce site. But in this list, I want the category name to appear first and below the items. Example:

  • Sports
  • Bike
  • Boots
  • Decoration
  • Carpet
  • Curtain

But it would still be nice to even indent the items. More or less like the following picture:

It's possible? How?

    
asked by anonymous 23.03.2018 / 20:35

2 answers

1

For this you have to use <optgroup> within <select>

See the example:

<select>
    <optgroup label="Category 1">
        <option>Item 1</option>
        <option>Item 2</option>
    </optgroup>
    <optgroup label="Category 2">
        <option>Item 3</option>
        <option>Item 4</option>
    </optgroup>
</select>
    
23.03.2018 / 20:45
1
  

Reference: link

<select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>
    
23.03.2018 / 20:46