HTML <optgroup> tag

定义和用法

<optgroup> 标签用于对 <select> 元素(下拉列表)中的相关选项进行分组。

如果您有很长的选项列表,使用相关选项的分组可以更方便用户处理。

另请参阅:

HTML DOM 参考手册:OptionGroup 对象

实例

使用 <optgroup> 标签对相关选项进行分组:

<label for="cars">请选择一个汽车品牌:</label>
<select  name="cars" id="cars">
  <optgroup label="中国车">
    <option value="byd">比亚迪</option>
    <option value="geely">吉利</option>
  </optgroup>
  <optgroup label="German cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

Try it yourself

Attribute

Attribute Value Description
disabled disabled Specifies that the option group should be disabled.
label Text Specifies the tag for the option group.

Global attributes

<optgroup> The tag also supports Global attributes in HTML.

Event attributes

<optgroup> The tag also supports Event attributes in HTML.

Default CSS settings

None.

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support