HTML <datalist> tagS2C Home   « HTML <datalist> tag

Definition

The <datalist> tag specifies a list of pre-defined <option> elements for an <input> tag allowing an autocomplete feature for the <input> tag.

The <datalist id=""> attribute must be the same value as the <input list=""> attribute to bind them together.

The <datalist> tag was introduced in HTML5.

Example


<label for="pies">Choose your pie shape from the list:</label>
<input list="pie" name="pies" id="pies">
<datalist id="pie">
  <option value="Round">
  <option value="Square">
  <option value="Hexagon">
  <option value="Star">
  <option value="Triangle">
</datalist>

When you enter any letter that appears in one of the options above, that option is made available in a drop down list, so for instance entering 'o' would bring up a list with 'Round' and 'Hexagon'.

After this the letters entered have to be in a sequence from the list, so entering 'ou' will reduce the list to 'Round' whereas entering 'od' will remove the list.

Attributes

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


<datalist> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <datalist> tag.
<datalist> 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.

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

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

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

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

<datalist accesskey="a">Option elements</datalist>
tabindexSpecifies a tab order for the element.

<datalist tabindex="1">Option elements</datalist>
Language
dirSpecifies the directional flow of the content.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<datalist onscroll="go()">Option elements</datalist> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - Advanced Forms