HTML <th> tagS2C Home   « HTML <th> tag

Definition

The <th> tag is used to define a heading 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 <th> tag.


<th> Specific Attributes
Attribute Value Description Example
abbrtextSpecifies a shorter text description of the contents of a cell and can be utilized by screen readers.

<th abbr="description">Table header content</th>
colspannumberSpecifies the number of columns a table cell should span.

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

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

<th rowspan="3">Table header content</th>
scopeSpecifies a way to associate columns and rows with heading information.

<th scope="colgroup">Table header content</th>
colCell is a column header.
colgroupCell is a column group heade
rowCell is a row header
rowgroupCell is a row group header
<th> 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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