HTML5 Reference

HTML <table> tag

Definition

The <table> tag is used to define a table.

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 <table> tag.


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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