<th> (Table Header)
This element specifies a header cell in a table. The element should occur within a table row as defined by a tr element. The main difference between this element and td is that browsers might render table headers slightly differently, usually bolding and centering contents. However, the element is logical in nature and should be used to structure tables.
Standard Syntax
<th
abbr="abbreviation"</th>
align="center | justify | left | right"
axis="group name"
bgcolor="color name | #RRGGBB" (transitional only)
char="character"
charoff="offset"
class="class name"
colspan="number"
dir="ltr | rtl"
headers="space-separated list of associated header
cells' id values"
height="pixels" (transitional only)
id="unique alphanumeric identifier"
lang="language code"
nowrap="nowrap" (transitional only)
rowspan="number"
scope="col | colgroup | row | rowgroup"
style="style information"
title="advisory text"
valign="baseline | bottom | middle | top"
width="pixels" (transitional only)
Nonstandard Attributes Commonly Supported
background="url of image file"
bordercolor="color name | #RRGGBB"
Attributes Defined by Internet Explorer
accesskey="key" (5.5)
bordercolordark="color name | #RRGGBB" (4)
bordercolorlight="color name | #RRGGBB" (4)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
tabindex="number" (5.5)
valign="center" (4)
Standard Event Attributes
onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup
Events Defined by Internet Explorer
onactivate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate,onbeforeeditfocus, onbeforepaste, onblur, oncontextmenu, oncontrolselect, oncopy, oncut, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onfilterchange, onfocus, onfocusin, onfocusout, onhelp, onlosecapture, onmouseenter, onmouseleave, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresizeend, onresizestart, onselectstart, ontimeerror
Element Specific Attributes
- abbr
- The value of this attribute is an abbreviated name for a header cell. This might be useful when attempting to display large tables on small screens.
- align
- This attribute is used to align the contents of the cells within the <tbody> element. Common values are center, justify, left, and right.
- axis
- This attribute is used to provide a name for a group of related headers.
- background
- This nonstandard attribute, which is supported by Internet Explorer, Netscape and WebTV, specifies the URL of a background image for the table cell. The image is tiled if it is smaller than the cell's dimensions.
- bgcolor
- This attribute specifies a background color for a table cell. Its value can be either a named color, such as red, or a color specified in the hexadecimal #RRGGBB format, such as #FF0000.
- bordercolor
- This attribute, supported by Internet Explorer and Netscape, is used to set the border color for a table cell. The attribute should be used only with a positive value for the border attribute. The value of the attribute can be either a named color, such as green, or a color specified in the hexadecimal #RRGGBB format, such as #00FF00.
- bordercolordark
- This Internet Explorer-specific attribute specifies the darker of two border colors used to create a three-dimensional effect for a cell's borders. It must be used with the border attribute set to a positive value. The attribute value can be either a named color, such as blue, or a color specified in the hexadecimal #RRGGBB format, such as #00FF00).
- bordercolorlight
- This Internet Explorer-specific attribute specifies the lighter of two border colors used to create a three-dimensional effect for a cell's borders. It must be used with the border attribute set to a positive value. The attribute value can be either a named color, such as red, or a color specified in the hexadecimal #RRGGBB format, such as #FF0000.
- char
- This attribute is used to define the character to which element contents are aligned when the align attribute is set to the char value.
- charoff
- This attribute contains an offset as a positive or negative integer to align characters as related to the char value. A value of 2, for example, would align characters in a cell two characters to the right of the character defined by the char attribute.
- colspan
- This attribute takes a numeric value that indicates how many columns wide a cell should be. This is useful to create tables with cells of different widths.
- headers
- This attribute takes a space-separated list of id values that correspond to the header cells related to this cell.
- height
- This attribute indicates the height in pixels of the header cell.
- nowrap
- This attribute keeps the content within a table header cell from automatically wrapping.
- rowspan
- This attribute takes a numeric value that indicates how many rows high a table cell should span. This attribute is useful in defining tables with cells of different heights.
- scope
- This attribute specifies the table cells for which the current cell provides header information. A value of col indicates that the cell is a header for the the rest of the column below it. A value of colgroup indicates that the cell is a header for its current column group. A value of row indicates that that the cell contains header information for the rest of the row it is in. A value of rowgroup indicates that the cell is a header for its row group. This attribute can be used in place of the header attribute and is useful for rendering assistance by nonvisual browsers. This attribute was added very late to the HTML 4.0 specification so support for this attribute is minimal.
- valign
- This attribute is used to set the vertical alignment for the table cell. HTML 4 defines baseline, bottom, middle, and top. Internet Explorer further defines center, which should act just like middle.
- width
- This attribute specifies the width of a header cell in pixels.
Examples
<table border="1">
<tr>
<th>Names</th>
<th>Apples</th>
<th>Oranges</th>
</tr>
<tr>
<td>Bobby</td>
<td>10</td>
<td>5</td>
</tr>
<tr>
<td>Ruby Sue</td>
<td>20</td>
<td>3</td>
</tr>
</table>
Compatibility
HTML 3.2, 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 2, 3, 4, 5, 5.5, 6
Netscape 1.1, 2, 3, 4, 4.5-4.8, 6, 7
Opera 4-7
Notes
The HTML 3.2 specification defines only align, colspan, height, nowrap, rowspan, valign, and width attributes.
This element should always be within the <tr> element.
Under the XHTML 1.0 specification, the closing </th> tag ceases to be optional.