HTML <data> tagS2C Home   « HTML <data> tag

Definition

The <data> tag is used for showing human-readable content along with a value that is machine-readable.

The <data> tag was introduced in HTML5.

Example


<table>
  <tr>
    <th>Fruit</th>
    <th>Colour</th>
    <th>Quantity</th>
  </tr>
  <tr>
    <td><data value="11111">Banana</data><td>
    <td>Yellow</td>
    <td>5</td>
  </tr>
  <tr>
    <td><data value="22222">Pea</data><td>
    <td>Green</td>
    <td>50</td>
  </tr>
</table>
Fruit Colour Quantity
Banana Yellow 5
Pea Green 50

In the example above we are giving each fruit a machine readable number via the <data> tag; this could for example be a stock number that a script could use for doing some processing on a particular kind of fruit.

Attributes

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


<data> Specific Attributes
Attribute Value Description Example
valuemachine-readable formatSpecifies the machine-readable format of the data content.
Required attribute.

<data value="22222">
<data> 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.

<data value="22222" class="name">Data value</data>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<data value="22222" id="name">Data value</data>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<data value="22222" style="color:red;">Data value</data>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<data value="22222" title="Content info">Data value</data>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<data value="22222" accesskey="a">Data value</data>
tabindexSpecifies a tab order for the element.

<data value="22222" tabindex="1">Data value</data>
Language
dirSpecifies the directional flow of the content.

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

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

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<data value="22222" translate="no">Data value</data> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<data value="22222" contenteditable="true">Data value</data> 
draggableSpecifies whether the element is draggable.

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

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

 <!-- Executes go() function -->
<data value="22222" oncopy="go()">Data value</data> 
oncutThe script to be run when the user cuts the content of an element.

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

 <!-- Executes go() function -->
<data value="22222" onpaste="go()">Data value</data>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<data value="22222" ondrag="go()">Data value</data>
ondragendThe script to be run when an element has stopped being dragged.

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

 <!-- Executes go() function -->
<data value="22222" ondragenter="go()">Data value</data>
ondragleaveThe script to be run when an element leaves a valid drop target.

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

 <!-- Executes go() function -->
<data value="22222" ondragover="go()">Data value</data>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<data value="22222" ondragstart="go()">Data value</data>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<data value="22222" ondrop="go()">Data value</data>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<data value="22222" onblur="go()">Data value</data>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<data value="22222" onchange="go()">Data value</data>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<data value="22222" oncontextmenu="go()">Data value</data>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<data value="22222" onfocus="go()">Data value</data>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<data value="22222" oninput="go()">Data value</data>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<data value="22222" oninvalid="go()">Data value</data>
onresetThe script to be run when a dragged element is being dropped.

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

 <!-- Executes go() function -->
<data value="22222" onselect="go()">Data value</data>
onsubmitThe script to be run when a form is submitted.

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

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

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

 <!-- Executes go() function -->
<data value="22222" onkeyup="go()">Data value</data>
Media
onabortThe script code to be run on abort.

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

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

 <!-- Executes go() function -->
<data value="22222" oncuechange="go()">Data value</data>
ondurationchangeThe script to be run when the length of the media is changed.

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

 <!-- Executes go() function -->
<data value="22222" onemptied="go()">Data value</data>
onendedThe script to be run when the media has reach the end.

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

 <!-- Executes go() function -->
<data value="22222" onloadeddata="go()">Data value</data>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<data value="22222" onloadedmetadata="go()">Data value</data>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<data value="22222" onloadstart="go()">Data value</data>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<data value="22222" onpause="go()">Data value</data>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<data value="22222" onplay="go()">Data value</data>
onplayingThe script to be run when when playback has already begun.

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

 <!-- Executes go() function -->
<data value="22222" onprogress="go()">Data value</data>
onratechangeThe script to be run when the playback rate changes.

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

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

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

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

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

 <!-- Executes go() function -->
<data value="22222" ontimeupdate="go()">Data value</data>
onvolumechangeThe script to be run when the volume has changed or been muted.

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

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

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

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

 <!-- Executes go() function -->
<data value="22222" onmousedown="go()">Data value</data>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<data value="22222" onmousemove="go()">Data value</data>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<data value="22222" onmouseout="go()">Data value</data>
onmouseoverThe script to be run when the mouse cursor moves over an element.

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

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

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

 <!-- Executes go() function -->
<data value="22222" onscroll="go()">Data value</data> 
Window - NONE

Relevant HTML Tutorials

Widgets / Miscellaneous