NOTICE: This website is no longer updated or supported - as such many of the techniques used to build it may seem antiquated in the modern day. It is preserved for historical reasons only.

HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<select> (Selection List)


This element defines a selection list within a form. Depending on the form of the selection list, the control allows the user to select one or more list options.

Standard Syntax


<select
class="class name(s)"
dir="ltr | rtl"
disabled="disabled"
id="unique alphanumeric identifier"
lang="language code"
multiple="multiple"
name="unique alphanumeric name"
size="number"
style="style information"
tabindex="number"
title="advisory text"

option and optgroup elements only
</select>

Attributes Defined by Internet Explorer


accesskey="character" (4)
align="absbottom | absmiddle | baseline | bottom | left | middle | right | texttop | top" (4)
datafld="column name" (4)
datasrc="data source ID" (4)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
unselectable="on | off" (5.5)

Standard Event Attributes


onblur, onchange, onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup

Events Defined by Internet Explorer


onactivate, onafterupdate, onbeforeactivate, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onbeforeupdate, oncontextmenu, oncontrolselect, oncut, ondeactivate, ondragenter, ondragleave, ondragover, ondrop, onerrorupdate, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, onselectstart

Element Specific Attributes


align
This Microsoft-specific attribute controls the alignment of the image with respect to the content on the page. The default value is left, but other values such as absbottom, absmiddle, baseline, bottom, middle, right, texttop, and top also might be supported. The meaning of these values should be similar to inserted objects such as images.

datafld
This attribute is used to indicate the column name in the data source that is bound to the options in the <select> element.

datasrc
The value of this attribute is set to an identifier indicating the data source to pull data from.

disabled
This attribute is used to turn off a form control. Elements will not be submitted nor can they receive any focus from the keyboard or mouse. Disabled form controls will not be part of the tabbing order. The browser also can gray out the form that is disabled in order to indicate to the user that the form control is inactive. This attribute requires no value.

multiple
This attribute allows the selection of multiple items in the selection list. The default is single-item selection.

name
This attribute allows a form control to be assigned a name so that it can be referenced by a scripting language. name is supported by older browsers such as Netscape 2 generation browsers, but the W3C encourages the use of the id attribute. For compatibility purposes both might have to be used.

size
This attribute sets the number of visible items in the selection list. When the multiple attribute is not present, only one entry should show; however, when multiple is present, this attribute is useful to set the size of the scrolling list box.

tabindex
This attribute takes a numeric value indicating the position of the form control in the tabbing index for the form. Tabbing proceeds from the lowest positive tabindex value to the highest. Negative values for tabindex will leave the form control out of the tabbing order. When tabbing is not explicitly set, the browser might tab through items in the order they are encountered. Form controls that are disabled due to the presence of the disabled attribute will not be part of the tabbing index, although read-only controls will be.

Examples


Choose your favorite colors
<select multiple size="2">
   <option>Red
   <option>Blue
   <option>Green
   <option>Yellow
</select>

Taco Choices
<select name="tacomenu">
   <option value="SuperChicken">
Chicken
   <option value="Baja">Fish
   <option value="RX-Needed">Carnitas
</select>

Compatibility


HTML 2, 3.2, 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 2, 3, 4, 5, 5.5, 6
Netscape 1, 2, 3, 4, 4.5-4.8, 6, 7
Opera 4-7

Notes


The HTML 4.01 specification reserves the attributes datafld and datasrc for future use, but these are removed under XHTML.

Internet Explorer's variant of the disabled attribute allows values of true and false, as well as the standard disabled value.

Under traditional HTML, the end tag </option> is often omitted.

Be careful of the name and id attribute problem that may occur, particularly when setting the multiple attribute. It may be better to have separate values.

The HTML 2.0 and 3.2 specifications define only multiple, name, and size attributes.

(X)HTML Elements
CSS Properties
Previous: script Next: small
< Home | About | Chapters | Examples | Errata | Reference | Site Map >