NOTICE: This website is no longer updated or supported - as such many of the techniques used to build it may seem antiquated in the modern day. It is preserved for historical reasons only.

HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<td> (Table Data)


This element specifies a data cell in a table. The element should occur within a table row as defined by the <tr> element.

Standard Syntax


<td
abbr="abbreviation"
align="center | justify | left | right"
axis="group name"
bgcolor="color name | #RRGGBB" (transitional only)
char="character"
charoff="offset"
class="class name"
colspan="number of columns to span"
dir="ltr | rtl"
headers="space-separated list of associated header cells' id values"
height="pixels or percentage" (transitional only)
id="unique alphanumeric identifier"
lang="language code"
nowrap="nowrap" (transitional only)
rowspan="number or rows to span"
scope="col | colgroup | row | rowgroup"
style="style information"
title="advisory text"
valign="baseline | bottom | middle | top"
width="pixels or percentage" (transitional only)
</td>

Nonstandard Attributes Commonly Supported


background="url of image file"
bordercolor="color name | #RRGGBB"

Attributes Defined by Internet Explorer


accesskey="key" (5.5)
background="url of image file" (4)
bordercolor="color name | #RRGGBB" (4)
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)
unselectable="on | off" (5.5)

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. Supported 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. (Netscape Navigator often fails to render a cell with a colored background unless a nonbreaking space, at least, is inserted in the cell.)

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 of the cell in pixels.

nowrap
This attribute keeps the content within a table 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 that the current cell provides header information for. 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 might 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 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 replaces middle with center; the effect should be the same.

width
This attribute specifies the width of a cell in pixels.

Examples


<table>
  <tr>
<td align="left" valign="top">

 Put me in the top left corner.</td>

<td align="right" bgcolor="red" valign="bottom">

 Put me in the bottom right corner.</td>
  </tr>
</table>


<table border="1" width="80%">
  <tr>
<td colspan="3">

A pretty wide cell</td>

  <tr>
<td>
Item 2</td>
<td>
Item 3</td>
<td>
Item 4</td>
  </tr>
</table>

Compatibility


HTML 3.2, 4, 4.1, 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


Under the XHTML 1.0 specification, the closing </td> tag ceases to be optional.

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.

(X)HTML Elements
CSS Properties
Previous: tbody Next: textarea
< Home | About | Chapters | Examples | Errata | Reference | Site Map >