HTML <select> tagS2C Home   « 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>

Required Attributes

NONE

Optional Attributes

autofocus - specifies a field to give focus to on page load.


<!-- Valid values are an empty string or autofocus -->
<select name="name" autofocus>Selectable options here</select>
<select name="name" autofocus="autofocus"></select>

disabled - specifies the selectable drop-down list will be disabled until a certain condition occurs.


<!-- Valid values are an empty string or disabled -->
<select name="name" disabled>Selectable options here</select>
<select name="name" disabled="disabled"></select>

form - specifies the form that the input element belongs to.


<select name="name" form="someForm">Selectable options here</select>

multiple - specifies the user can enter more than one value in a field.


<!-- To select multiple option hold down CTRL on Windows or command button on Mac -->
<!-- Valid values are an empty string or multiple -->
<select name="name" multiple>Selectable options here</select>
<select name="name" multiple="multiple">Selectable options here</select>

name - specifies a name for the selectable drop-down list.


<select name="name">Selectable options here</select>

required - specifies the user must select an option before form submission.


<!-- Valid values are an empty string or required -->
<select name="name" required>Selectable options here</select>
<select name="name" required="required">Selectable options here</select>

size - specifies the viewable options in the selectable drop-down list.


<select name="name" size="3">Selectable options here</select>

Global Attributes

Common

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<select class="classname">Selectable options here</select>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<select id="idname">Selectable options here</select>

style - specifies an inline style for the element allowing you to apply the style to the content.


<select style="color:red;text-align:left">Selectable options here</select>

tabindex - specifies the tab order of the element.


<select tabindex="1">Selectable options here</select>

title - specifies extra information about the content.


<select title="information about the content">Selectable options here</select>

Keyboard

accesskey - specifies a keyboard shortcut to associate with the element.


<select accesskey="aKeyValue">Selectable options here</select>

tabindex - specifies a tab order for the element.


<select tabindex="someNumber">Selectable options here</select>
select

Language

dir - specifies the directional flow of the content.


<select dir="ltr">Selectable options here</select>   <!-- The text will flow from left to right -->
<select dir="rtl">Selectable options here</select>   <!-- The text will flow from right to left -->

lang - specifies a language code for the content of the element.


<select lang="en">Selectable options here</select>

xml:lang - specifies a language code for the content of the element in XHTML documents.


<select xml:lang="fr">Selectable options here</select>

spellcheck - specifies whether the element is to have its spelling checked.


<!-- Valid values are true and  false - default is inherited / browser specific. -->
<select spellcheck="true">Selectable options here</select>

translate - specifies whether the content of the element can be translated.


<!-- Valid values are yes and  no - default is yes. -->
<select translate="no">Selectable options here</select> 

Miscellaneous

contenteditable - specifies whether the content of the element is editable.


<!-- Valid values are true and  false - default is inherited. -->
<select contenteditable="false">Selectable options here</select> 

draggable - specifies whether the the element is draggable.

Only text selections, images, and links can be dragged.


<!-- Valid values are true and  false - default is browser specific. -->
<select draggable="true">Selectable options here</select>

hidden - specifies whether the element is not yet, or no longer, relevant.


<!-- Valid values are an empty string or hidden -->
<select hidden>Selectable options here</select> 
<select hidden="hidden">Selectable options here</select> 

Event Attributes

Document

onabort - The JavaScript code to be run on abort.


<section onabort="go()">Selectable options here</select>   <!-- Executes the go() function -->

onerror - The JavaScript code to be run when an error occurs when the file is being loaded.


<section onerror="go()">Selectable options here</select>   <!-- Executes the go() function -->

onload - The JavaScript code to be run when the document is loaded.


<section onload="go()">Selectable options here</select>   <!-- Executes the go() function -->

onresize - The JavaScript code to be run when the browser window is resized.


<section onresize="go()">Selectable options here</select>   <!-- Executes the go() function -->

onscroll - The JavaScript code to be run when the scrollbar of an element is being scrolled.


<section onscroll="go()">Selectable options here</select>   <!-- Executes the go() function -->

onunload - The JavaScript code to be run once a page has unloaded or the browser window has been closed.


<section onunload="go()">Selectable options here</select>   <!-- Executes the go() function -->

Document Element

oncopy - The JavaScript code to be run when the user copies the content of an element.


<section oncopy="go()">Selectable options here</select>   <!-- Executes the go() function -->

oncut - The JavaScript code to be run when the user cuts the content of an element.


<section oncut="go()">Selectable options here</select>   <!-- Executes the go() function -->

onpaste - The JavaScript code to be run when the user pastes some content into an element.


<section onpaste="go()">Selectable options here</select>   <!-- Executes the go() function -->

Drag and Drop

ondrag - The JavaScript code to be run when an element is dragged.


<section ondrag="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondragend - The JavaScript code to be run when an element has stopped being dragged.


<section ondragend="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondragenter - The JavaScript code to be run when an element has been dragged to a valid drop target.


<section ondragenter="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondragleave - The JavaScript code to be run when an element leaves a valid drop target.


<section ondragleave="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondragover - The JavaScript code to be run when an element is being dragged over a valid drop target.


<section ondragover="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondragstart - The JavaScript code to be run at the start of a drag operation.


<section ondragstart="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondrop - The JavaScript code to be run when dragged element is being dropped.


<section ondrop="go()">Selectable options here</select>   <!-- Executes the go() function -->

Form

onblur - The JavaScript code to be run on abort.


<section onblur="go()">Selectable options here</select>   <!-- Executes the go() function -->

onchange - The JavaScript code to be run when object changed and attempt to leave field.


<section onchange="go()">Selectable options here</select>   <!-- Executes the go() function -->

oncontextmenu - The JavaScript code to be run when a context menu is triggered.


<section oncontextmenu="go()">Selectable options here</select>   <!-- Executes the go() function -->

onfocus - The JavaScript code to be run when the element gets focus.


<section onfocus="go()">Selectable options here</select>   <!-- Executes the go() function -->

oninput - The JavaScript code to be run when an element gets user input.


<section oninput="go()">Selectable options here</select>   <!-- Executes the go() function -->

oninvalid - The JavaScript code to be run when an element is invalid.


<section oninvalid="go()">Selectable options here</select>   <!-- Executes the go() function -->

onreset - The JavaScript code to be run when the reset button of a form is clicked.


<section onreset="go()">Selectable options here</select>   <!-- Executes the go() function -->

onselect - The JavaScript code to be run when some or all of the contents of an object are selected.


<section onselect="go()">Selectable options here</select>   <!-- Executes the go() function -->

onsubmit - The JavaScript code to be run when a form is submitted.


<section onsubmit="go()">Selectable options here</select>   <!-- Executes the go() function -->

Keyboard

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<select onkeydown="go()">Selectable options here</select>   <!-- Executes the go() function -->

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<select onkeypress="go()">Selectable options here</select>   <!-- Executes the go() function -->

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<select onkeyup="go()">Selectable options here</select>   <!-- Executes the go() function -->

Media

oncanplay - The JavaScript code to be run when a file has buffered enough so it is ready to start playing.


<section oncanplay="go()">Selectable options here</select>   <!-- Executes the go() function -->

oncanplaythrough - The JavaScript code to be run when a file can be played all the way to the end without further need of buffering.


<section oncanplaythrough="go()">Selectable options here</select>   <!-- Executes the go() function -->

oncuechange - The JavaScript code to be run when the cue changes when using the track element.


<section oncuechange="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondurationchange - The JavaScript code to be run when the length of the media is changed.


<section ondurationchange="go()">Selectable options here</select>   <!-- Executes the go() function -->

onemptied - The JavaScript code to be run when a media resource element suddenly becomes empty, usually due to an error.


<section onemptied="go()">Selectable options here</select>   <!-- Executes the go() function -->

onended - The JavaScript code to be run when the media has reach the end.


<section onended="go()">Selectable options here</select>   <!-- Executes the go() function -->

onloadeddata - The JavaScript code to be run when media data is loaded and playback can start.


<section onloadeddata="go()">Selectable options here</select>   <!-- Executes the go() function -->

onloadedmetadata - The JavaScript code to be run when metadata has been loaded.


<section onloadedmetadata="go()">Selectable options here</select>   <!-- Executes the go() function -->

onloadstart - The JavaScript code to be run when the media resource has started loading.


<section onloadstart="go()">Selectable options here</select>   <!-- Executes the go() function -->

onpause - The JavaScript code to be run when the media resource has been paused.


<section onpause="go()">Selectable options here</select>   <!-- Executes the go() function -->

onplay - The JavaScript code to be run when the media resource starts playback.


<section onplay="go()">Selectable options here</select>   <!-- Executes the go() function -->

onplaying - The JavaScript code to be run when playback has already begun.


<section onplaying="go()">Selectable options here</select>   <!-- Executes the go() function -->

onprogress - The JavaScript code to be run when the browser is fetching the media data.


<section onprogress="go()">Selectable options here</select>   <!-- Executes the go() function -->

onratechange - The JavaScript code to be run when the playback rate changes.


<section onratechange="go()">Selectable options here</select>   <!-- Executes the go() function -->

onseeked - The JavaScript code to be run when the seeking attribute is set to false indicating that seeking has finished.


<section onseeked="go()">Selectable options here</select>   <!-- Executes the go() function -->

onseeking - The JavaScript code to be run hen the seeking attribute is set to true indicating that seeking is currently active.


<section onseeking="go()">Selectable options here</select>   <!-- Executes the go() function -->

onstalled - The JavaScript code to be run when the browser is unable to continue fetching media data.


<section onstalled="go()">Selectable options here</select>   <!-- Executes the go() function -->

onsuspend - The JavaScript code to be run when media data has stopped before being completely loaded.


<section onsuspend="go()">Selectable options here</select>   <!-- Executes the go() function -->

ontimeupdate - The JavaScript code to be run when the media resources current playback position has changed.


<section ontimeupdate="go()">Selectable options here</select>   <!-- Executes the go() function -->

onvolumechange - The JavaScript code to be run when the volume has changed or been muted.


<section onvolumechange="go()">Selectable options here</select>   <!-- Executes the go() function -->

onwaiting - The JavaScript code to be run when the media resource has paused but is expected to resume.


<section onwaiting="go()">Selectable options here</select>   <!-- Executes the go() function -->

Mouse

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<select onclick="go()">Selectable options here</select>   <!-- Executes the go() function -->

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<select ondblclick="go()">Selectable options here</select>   <!-- Executes the go() function -->

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<select onmousedown="go()">Selectable options here</select>   <!-- Executes the go() function -->

onmousemove - The JavaScript code to be run when the mouse button is moved.


<select onmousemove="go()">Selectable options here</select>   <!-- Executes the go() function -->

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<select onmouseout="go()">Selectable options here</select>   <!-- Executes the go() function -->

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<select onmouseover="go()">Selectable options here</select>   <!-- Executes the go() function -->

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<select onmouseup="go()">Selectable options here</select>   <!-- Executes the go() function -->

onwheel - The JavaScript code to be run when the mouse wheel rolls up or down over an element.


<section onwheel="go()">Selectable options here</select>   <!-- Executes the go() function -->

Window

NONE

go to home page Homepage go to top of page Top