Code has been added to clipboard!

HTML optgroup Tag

Reading time 1 min
Published Jun 29, 2017
Updated Oct 2, 2019

HTML optgroup: Main Tips

  • HTML optgroup element enables grouping related options within a dropdown menu.
  • It is a child of a <select> element and a parent to <option> elements.
  • optgroup stands for HTML option group.
  • HTML optgroup tags support all global attributes.

Defining HTML Option Groups

When you're using HTML select, option groups may prove useful as they simplify the selection for users. Using HTML <optgroup> tags, you can select optgroups and define them using a label:

Example
<select>
  <optgroup label="Sports">
    <option value="baseball">Baseball</option>
    <option value="basketball">Basketball</option>
  </optgroup>
  <optgroup label="Shopping">
    <option value="food">Food</option>
    <option value="gift">Gift</option>
  </optgroup>
</select>

Two optgroup Tag Attributes

You have to include the label attribute when using HTML optgroup tags. It defines the name for the HTML option group, and the browser will use its value for labeling the groups for the user:

Example
<select>
  <optgroup label="Main">
    <option value="beef">Beef with broccoli</option>
    <option value="chicken">Chicken Teriyaki</option>
  </optgroup>
  <optgroup label="Dessert">
    <option value="hot">Chocolate lava cake</option>
    <option value="cold">Banana split</option>
  </optgroup>
</select>

disabled disables the selection of a specific group. Most browsers also show the disabled options in grey text:

Example
<select>
  <optgroup label="Destination">
    <option value="cuba">Cuba</option>
    <option value="hawaii">Hawaii</option>
  </optgroup>
  <optgroup label="Time" disabled>
    <option value="week">7 days</option>
    <option value="2weeks">14 days</option>
  </optgroup>
</select>

Browser support

Chrome
1+
Edge
All
Firefox
1+
IE
5.5+
Opera
All
Safari
All

Mobile browser support

Chrome
All
Firefox
4+
Opera
All
Safari
All
Basics
Introduction
Syntax
Editors
Basic Examples
Head Section
<!DOCTYPE>
Tags and Elements
Semantic Elements
Tags Reference
Attributes
Comments
Block and Inline Elements
Forms
Form Elements
Input
Responsive Web Design
Inline Scripts
Uniform Resource Locator
Redirect
XHTML
Geolocation
Drag and Drop
Local Storage
Web Workers
Server-Sent Events
Character Encoding
Text Formatting
Quotation and Citation Elements
Headings
Paragraphs
Links
Tables
Lists
Symbols
Space
Tab
Styles
Computer Code
Layout
Classes
Colors
Images
iframes
Audio Player
Video Player
YouTube Videos
Multimedia
Canvas
SVG
<!-- -->
<a>
<abbr>
<acronym> DEPRECATED
<address>
<applet> DEPRECATED
<article>
<aside>
<audio>
<b>
<base>
<basefont> DEPRECATED
<bdi>
<bdo>
<big> DEPRECATED
<blink> DEPRECATED
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center> DEPRECATED
<cite>
<code>
<col>
<colgroup>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir> DEPRECATED
<div>
<dl>
<dt>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font> DEPRECATED
<footer>
<form>
<frame> DEPRECATED
<frameset> DEPRECATED
<h1> – <h6>
<head>
<header>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<keygen> DEPRECATED
<label>
<legend>
<li>
<link>
<main>
<map>
<mark>
<menu>
<menuitem> DEPRECATED
<meta>
<meter>
<nav>
<noframes> DEPRECATED
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike> DEPRECATED
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt> DEPRECATED
<u>
<ul>
<var>
<video>
<wbr>