HTML5 Reference

HTML <option> tag

Definition

The <option> tag is used to define a selectable option in a drop-down list.

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 <option> tag.


<option> Specific Attributes
Attribute Value Description Example
labeltextSpecifies an alternative (more concise) description of the <option> items contents.

<option value="someValue"
        label="conciselabel">Option name</ol>
disabledValid values an empty string or disabledSpecifies the option will be disabled until a certain condition occurs.

<option value="someValue"
        disabled>Option name</option>
<option value="someValue"
        disabled="disabled">Option name</option>
selectedValid values an empty string or selectedSpecifies the option will be selected and viewable by default.

<option value="someValue"
        selected>Option name</option>
<option value="someValue"
        selected="selected">Option name</option>
valuetextSpecifies a value to send to the server instead of the element content.

<option value="someValue">Option name</option>
<option> 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.

<code class="name">Option name</option>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<code id="name">Option name</option>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<code style="color:red;">Option name</option>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<code title="Content info">Option name</option>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<code accesskey="a">Option name</option>
tabindexSpecifies a tab order for the element.

<code tabindex="1">Option name</option>
Language
dirSpecifies the directional flow of the content.

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

<code lang="en">Option name</option>
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. -->
<code spellcheck="true">Option name</option> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<code translate="no">Option name</option> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<code contenteditable="true">Option name</option> 
draggableSpecifies whether the element is draggable.

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

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

 <!-- Executes go() function -->
<code oncopy="go()">Option name</option> 
oncutThe script to be run when the user cuts the content of an element.

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

 <!-- Executes go() function -->
<code onpaste="go()">Option name</option>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<code ondrag="go()">Option name</option>
ondragendThe script to be run when an element has stopped being dragged.

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

 <!-- Executes go() function -->
<code ondragenter="go()">Option name</option>
ondragleaveThe script to be run when an element leaves a valid drop target.

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

 <!-- Executes go() function -->
<code ondragover="go()">Option name</option>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<code ondragstart="go()">Option name</option>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<code ondrop="go()">Option name</option>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<code onblur="go()">Option name</option>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<code onchange="go()">Option name</option>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<code oncontextmenu="go()">Option name</option>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<code onfocus="go()">Option name</option>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<code oninput="go()">Option name</option>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<code oninvalid="go()">Option name</option>
onresetThe script to be run when a dragged element is being dropped.

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

 <!-- Executes go() function -->
<code onselect="go()">Option name</option>
onsubmitThe script to be run when a form is submitted.

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

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

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

 <!-- Executes go() function -->
<code onkeyup="go()">Option name</option>
Media
onabortThe script code to be run on abort.

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

 <!-- Executes go() function -->
<code oncanplay="go()">Option name</option>
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 -->
<code oncanplaythrough="go()">Option name</option>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<code oncuechange="go()">Option name</option>
ondurationchangeThe script to be run when the length of the media is changed.

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

 <!-- Executes go() function -->
<code onemptied="go()">Option name</option>
onendedThe script to be run when the media has reach the end.

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

 <!-- Executes go() function -->
<code onloadeddata="go()">Option name</option>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<code onloadedmetadata="go()">Option name</option>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<code onloadstart="go()">Option name</option>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<code onpause="go()">Option name</option>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<code onplay="go()">Option name</option>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<code onplaying="go()">Option name</option>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<code onprogress="go()">Option name</option>
onratechangeThe script to be run when the playback rate changes.

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

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

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

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

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

 <!-- Executes go() function -->
<code ontimeupdate="go()">Option name</option>
onvolumechangeThe script to be run when the volume has changed or been muted.

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

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

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

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

 <!-- Executes go() function -->
<code onmousedown="go()">Option name</option>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<code onmousemove="go()">Option name</option>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<code onmouseout="go()">Option name</option>>
onmouseoverThe script to be run when the mouse cursor moves over an element.

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

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

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

 <!-- Executes go() function -->
<code onscroll="go()">Option name</option> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - Advanced Forms