HTML5 Reference

HTML <optgroup> tag

Definition

The <optgroup> tag is used to define a group of related options.

Example


<select>
  <optgroup label="Standard Pie Shapes">
    <option value="round">round</option>
    <option value="square">square</option>
  </optgroup>
  <optgroup label="Custom Pie Shapes">
    <option value="heart">heart</option>
    <option value="star">star</option>
    <option value="triangle">triangle</option>
  </optgroup>
</select>

Attributes

The following attributes can be used with the <optgroup> tag.


<optgroup> Specific Attributes
Attribute Value Description Example
labeltextSpecifies the viewable title of a group of options. Required

<optgroup label="labelName">Place options here</ol>
disabledValid values an empty string or disabledSpecifies the optgroup will be disabled until a certain condition occurs.

<optgroup label="labelName"
      disabled>Place options here</optgroup>
<optgroup label="labelName"
      disabled="disabled">Place options here</optgroup>
<optgroup> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<optgroup class="name">Options here</optgroup>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<optgroup id="name">Options here</optgroup>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<optgroup style="color:red;">Options here</optgroup>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<optgroup title="Content info">Options here</optgroup>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<optgroup accesskey="a">Options here</optgroup>
tabindexSpecifies a tab order for the element.

<optgroup tabindex="1">Options here</optgroup>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<optgroup dir="ltr">Options here</optgroup>
<!-- The text will flow from right to left -->
<optgroup dir="rtl">Options here</optgroup>
langSpecifies a language code for the content of the element.

<optgroup lang="en">Options here</optgroup>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited/browser specific. -->
<optgroup spellcheck="true">Options here</optgroup> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<optgroup translate="no">Options here</optgroup> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<optgroup contenteditable="true">Options here</optgroup> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<optgroup draggable="true">Options here</optgroup>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<optgroup hidden>Options here</optgroup> 
<optgroup hidden="hidden">Options here</optgroup> 
<optgroup> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<optgroup oncopy="go()">Options here</optgroup> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<optgroup oncut="go()">Options here</optgroup>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<optgroup onpaste="go()">Options here</optgroup>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<optgroup ondrag="go()">Options here</optgroup>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<optgroup ondragend="go()">Options here</optgroup>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<optgroup ondragenter="go()">Options here</optgroup>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<optgroup ondragleave="go()">Options here</optgroup>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<optgroup ondragover="go()">Options here</optgroup>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<optgroup ondragstart="go()">Options here</optgroup>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<optgroup ondrop="go()">Options here</optgroup>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<optgroup onblur="go()">Options here</optgroup>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<optgroup onchange="go()">Options here</optgroup>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<optgroup oncontextmenu="go()">Options here</optgroup>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<optgroup onfocus="go()">Options here</optgroup>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<optgroup oninput="go()">Options here</optgroup>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<optgroup oninvalid="go()">Options here</optgroup>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<optgroup onreset="go()">Options here</optgroup>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<optgroup onselect="go()">Options here</optgroup>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<optgroup onsubmit="go()">Options here</optgroup>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<optgroup onkeydown="go()">Options here</optgroup>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<optgroup onkeypress="go()">Options here</optgroup>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<optgroup onkeyup="go()">Options here</optgroup>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<optgroup onabort="go()">Options here</optgroup>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<optgroup oncanplay="go()">Options here</optgroup>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<optgroup oncanplaythrough="go()">Options here</optgroup>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<optgroup oncuechange="go()">Options here</optgroup>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<optgroup ondurationchange="go()">Options here</optgroup>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<optgroup onemptied="go()">Options here</optgroup>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<optgroup onended="go()">Options here</optgroup>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<optgroup onloadeddata="go()">Options here</optgroup>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<optgroup onloadedmetadata="go()">Options here</optgroup>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<optgroup onloadstart="go()">Options here</optgroup>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<optgroup onpause="go()">Options here</optgroup>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<optgroup onplay="go()">Options here</optgroup>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<optgroup onplaying="go()">Options here</optgroup>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<optgroup onprogress="go()">Options here</optgroup>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<optgroup onratechange="go()">Options here</optgroup>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<optgroup onseeked="go()">Options here</optgroup>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<optgroup onseeking="go()">Options here</optgroup>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<optgroup onstalled="go()">Options here</optgroup>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<optgroup onsuspend="go()">Options here</optgroup>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<optgroup ontimeupdate="go()">Options here</optgroup>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<optgroup onvolumechange="go()">Options here</optgroup>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<optgroup onwaiting="go()">Options here</optgroup>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<optgroup onclick="go()">Options here</optgroup>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<optgroup ondblclick="go()">Options here</optgroup>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<optgroup onmousedown="go()">Options here</optgroup>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<optgroup onmousemove="go()">Options here</optgroup>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<optgroup onmouseout="go()">Options here</optgroup>>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<optgroup onmouseover="go()">Options here</optgroup>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<optgroup onmouseup="go()">Options here</optgroup>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<optgroup onwheel="go()">Options here</optgroup>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<optgroup onscroll="go()">Options here</optgroup> 
Window - NONE

Relevant HTML Tutorials

HTML Lessons - Forms