Tag <td> HTML Reference



Example

A simple HTML table, with three table cells:

<table border="1">
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
</table>

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

1. Definition and Usage

The <td> tag defines a standard cell in an HTML table.

An HTML table has two kinds of cells:

  • Header cells - contains header information (created with the <th> element)
  • Standard cells - contains data (created with the <td> element)

The text in <th> elements are bold and centered by default.

The text in <td> elements are regular and left-aligned by default.


2. Tips and Notes

Tip: Use the colspan and rowspan attributes to let the content span over multiple columns or rows!


3. Differences Between HTML and XHTML

None


4. Optional Attributes

DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.

AttributeValueDescriptionDTD
abbrtextSpecifies an abbreviated version of the content in a cellSTF
alignleft
right
center
justify
char
Aligns the content in a cellSTF
axiscategory_nameCategorizes cellsSTF
bgcolorrgb(x,x,x)
#xxxxxx
colorname
Deprecated. Use styles instead.
Specifies the background color of a cell
TF
charcharacterAligns the content in a cell to a characterSTF
charoffnumber Sets the number of characters the content will be aligned from the character specified by the char attributeSTF
colspannumberSpecifies the number of columns a cell should spanSTF
headersheader_idSpecifies one or more header cells a cell is related toSTF
heightpixels
%
Deprecated. Use styles instead.
Sets the height of a cell
TF
nowrapnowrapDeprecated. Use styles instead.
Specifies that the content inside a cell should not wrap
TF
rowspannumberSets the number of rows a cell should spanSTF
scopecol
colgroup
row
rowgroup
Defines a way to associate header cells and data cells in a tableSTF
valigntop
middle
bottom
baseline
Vertical aligns the content in a cellSTF
widthpixels
%
Deprecated. Use styles instead.
Specifies the width of a cell
TF

5. Standard Attributes

The <td> tag supports the following standard attributes:

AttributeValueDescriptionDTD
classclassnameSpecifies a classname for an elementSTF
dirrtl
ltr
Specifies the text direction for the content in an elementSTF
ididSpecifies a unique id for an elementSTF
langlanguage_codeSpecifies a language code for the content in an elementSTF
stylestyle_definitionSpecifies an inline style for an elementSTF
titletextSpecifies extra information about an elementSTF
xml:langlanguage_codeSpecifies a language code for the content in an element, in XHTML documentsSTF

6. Event Attributes

The <td> tag supports the following event attributes:

AttributeValueDescriptionDTD
onclickscriptScript to be run on a mouse clickSTF
ondblclickscriptScript to be run on a mouse double-clickSTF
onmousedownscriptScript to be run when mouse button is pressedSTF
onmousemovescriptScript to be run when mouse pointer movesSTF
onmouseoutscriptScript to be run when mouse pointer moves out of an elementSTF
onmouseoverscriptScript to be run when mouse pointer moves over an elementSTF
onmouseupscriptScript to be run when mouse button is releasedSTF
onkeydownscriptScript to be run when a key is pressedSTF
onkeypressscriptScript to be run when a key is pressed and releasedSTF
onkeyupscriptScript to be run when a key is releasedSTF

Relative articles