HTML <td> tagS2C Home   « HTML <td> tag

Definition

The <td> tag is used to define a table cell within a table and must be nested within the <tr> element.

Example


<table>
  <tr>
    <th>Fruit</th>
    <th>Colour</th>
  </tr>
  <tr>
    <td>Banana</td>
    <td>Yellow</td>
  </tr>
  <tr>
    <td>Pea</td>
    <td>Green</td>
  </tr>
</table>
Fruit Colour
Banana Yellow
Pea Green

Attributes

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


<td> Specific Attributes
Attribute Value Description Example
colspannumberSpecifies the number of columns a table cell should span.

<td colspan="3">Table data content</td>
headersheader-idSpecifies a space separated list of header cells the table cell is related to.

<td headers="someValue">Table data content</td>
rowspannumberSpecifies the number of rows a table cell should span.

<td rowspan="3">Table data content</td>
<td> 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.

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

<td id="name">Table data content</td>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

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

<td title="Content info">Table data content</td>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<td accesskey="a">Table data content</td>
tabindexSpecifies a tab order for the element.

<td tabindex="1">Table data content</td>
Language
dirSpecifies the directional flow of the content.

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

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

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

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<td contenteditable="true">Table data content</td> 
draggableSpecifies whether the element is draggable.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 <!-- Executes go() function -->
<td onscroll="go()">Table data content</td> 
Window - NONE