HTML5 Reference

HTML <select> tag

Definition

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

Use the <label> HTML tag to give the select control a description and to aid accessibility.

Example


<label for="pieshape">Pie shape selector: </label>
<select id="pieshape">  
  <optgroup label="Normal">
    <option value="round">round</option>
    <option value="square">square</option>
  </optgroup>
  <optgroup label="Custom">
    <option value="hexagon">hexagon</option>
    <option value="star">star</option>
    <option value="triangle">triangle</option>
  </optgroup>
</select>

Attributes

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


<select> Specific Attributes
Attribute Value Description Example
autofocusempty string or autofocusGives focus to this selectable drop-down list on page load.

<select name="name" 
        autofocus>Selectable options</select>
<select name="name" 
        autofocus="autofocus">Selectable options</select>
disabledempty string or disabledSpecifies the selectable drop-down list will be disabled until a certain condition occurs.

<select name="name" 
        disabled>Selectable options</select>
<select name="name" 
        disabled="disabled">Selectable options</select>
formform idSpecifies the form that the selectable drop-down list belongs to

<select name="name" 
        form="formId">Selectable options</select>
multiple empty string or multipleSpecifies that multiple options can be selected.

<select name="name" 
        multiple>Selectable options</select>
<select name="name" 
        multiple="multiple">Selectable options</select>
namenameSpecifies a name for the selectable drop-down list.

<select 
        name="name">Selectable options</select>
required empty string or requiredSpecifies the user must select an option before form submission.

<select name="name" 
        required>Selectable options</select>
<select name="name" 
        required="required">Selectable options</select>
sizetextSpecifies the viewable options in the selectable drop-down list.



Value must be numeric and greater than zero - default value is 1.

<select name="name" 
        size="3">Selectable options</select>
<select> 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.

<select class="name">Selectable options</select>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<select id="name">Selectable options</select>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<select style="color:red;">Selectable options</select>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<select title="Content info">Selectable options</select>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<select accesskey="a">Selectable options</select>
tabindexSpecifies a tab order for the element.

<select tabindex="1">Selectable options</select>
Language
dirSpecifies the directional flow of the content.

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

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

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

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<select contenteditable="true">Selectable options</select> 
draggableSpecifies whether the element is draggable.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<select onkeyup="go()">Selectable options</select>
Media
onabortThe script code to be run on abort.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<select onscroll="go()">Selectable options</select> 
Window - NONE

Relevant HTML Tutorials

HTML Lessons - Forms