Little Web Hut

HTML 4.01 and XHTML 1.0 Reference: <td> Tag

HTML <td> Tag - Table Data Cell
Syntax This element uses separate opening and closing tags.
<td>...</td>
Usage The <td> tag is used to define a data cell that is used within a table. Each cell in a table can contain either header information or data. The header information is defined using the <th> tag and the data is defined using the <td> tag. The <th> tag can also be used by non-visual browsers to make the data more accessible.

HTML & XHTML <td> tag example also using the <th> tag for row headers.
<table border="1">
 <tr>
  <th colspan="3">Stock Tracker</th>
 </tr>
 <tr>
  <th>Stock Symbol</th>
  <td>MSFT</td>
  <td>GOOG</td>
 </tr>
 <tr>
  <th>Profit</th>
  <td>$723.48</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

Content Model The <td> element can contain the following tags, and Text, between its opening and closing tags.Notes:
1. The <td> element can contain the <iframe> tag when using DTD Transitional and Frameset documents but not Strict documents.
2. The <td> element can contain the <noframes> tag when using DTD Transitional documents but not Strict or Frameset documents.
3. Red tags have been deprecated and are allowed in DTD Transitional and Frameset documents but not Strict documents.

Red attributes have been deprecated
<td> Tag Attribute Summary
Required Tag Specific Core Focus Events Language
  abbr align axis bgcolor char charoff colspan headers height nowrap rowspan scope valign width id class style title   onclick ondblclick onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup dir lang xml:lang1
Notes: 1. XHTML only.

Red attributes have been deprecated
<td> Tag Attributes
Attribute Description
abbrThe abbr attribute can be used to provide an abbreviation of the cell's content.
alignThe align attribute specifies the horizontal alignment within a cell. Possible values are "center", "char", "justify", "left", and "right".

HTML & XHTML <td> example using multiple attributes.
<table border="1">
 <tr>
  <th colspan="4">Stock Tracker</th>
 </tr>
 <tr>
  <th rowspan="3" valign="top">April Results</th>
  <th scope="row">Stock Symbol</th>
  <td>MSFT</td>
  <td>GOOG</td>
 </tr>
 <tr>
  <th scope="row">Profit</th>
  <td align="right" bgcolor="#FFFF00" width="100">$723.48</td>
  <td align="right" bgcolor="yellow" width="100">$1254.58</td>
 </tr>
 <tr>
  <th scope="row">Total</th>
  <td align="center" colspan="2">$1978.06</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

axisThe axis attribute can be used to place the cell into conceptual categories by providing a comma separated list of category names.
bgcolorThe bgcolor attribute specifies the background color of the cell. The color value can be expressed as an sRGB value which is a hash (#) symbol followed by a hexadecimal value. Or, the color value can be expressed as a color name. Color names are black, silver, gray, white, maroon, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, or aqua.

HTML & XHTML <td> example using multiple attributes.
<table border="1">
 <tr>
  <th colspan="4">Stock Tracker</th>
 </tr>
 <tr>
  <th rowspan="3" valign="top">April Results</th>
  <th scope="row">Stock Symbol</th>
  <td>MSFT</td>
  <td>GOOG</td>
 </tr>
 <tr>
  <th scope="row">Profit</th>
  <td align="right" bgcolor="#FFFF00" width="100">$723.48</td>
  <td align="right" bgcolor="yellow" width="100">$1254.58</td>
 </tr>
 <tr>
  <th scope="row">Total</th>
  <td align="center" colspan="2">$1978.06</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style


Note: This attribute has been deprecated.
charThe char attribute specifies a single character to act as an alignment character when the align attribute is set to "char". The default character for this attribute is the decimal point.

Note: This attribute may have little or no browser support among popular browsers.
charoffThe charoff attribute specifies an offset to the first occurrence of the alignment character, which is specified by the char attribute.

Note: This attribute may have little or no browser support among popular browsers.
colspanThe colspan attribute specifies how many columns that the cell spans. A value of "1" is the default for this attribute.

HTML & XHTML <td> example using multiple attributes.
<table border="1">
 <tr>
  <th colspan="4">Stock Tracker</th>
 </tr>
 <tr>
  <th rowspan="3" valign="top">April Results</th>
  <th scope="row">Stock Symbol</th>
  <td>MSFT</td>
  <td>GOOG</td>
 </tr>
 <tr>
  <th scope="row">Profit</th>
  <td align="right" bgcolor="#FFFF00" width="100">$723.48</td>
  <td align="right" bgcolor="yellow" width="100">$1254.58</td>
 </tr>
 <tr>
  <th scope="row">Total</th>
  <td align="center" colspan="2">$1978.06</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

headersThe headers attribute specifies header cells that provide information about the current cell. The value for this attribute is a space separated list of names. Each name in the list corresponds to an id attribute of a header cell. This attribute may make the cell's contents more accessible for non-visual browsers.
heightThe height attribute is used to specify the cell height. The value is in pixels, or percentage when followed by a percent sign (%). If the value is specified as a percentage, it refers to a percentage of the available space.

HTML & XHTML <td> example using the scope, height, rowspan and valign attributes.
<table border="1">
 <tr>
  <th scope="col">Ticker Symbol</th>
  <th scope="col">Profit</th>
  <th scope="col">Total</th>
 </tr>
 <tr>
  <td scope="row" height="50">MSFT</td>
  <td>$723.48</td>
  <td rowspan="2" valign="middle">$1978.06</td>
 </tr>
 <tr>
  <td scope="row" height="50">GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style


Note: This attribute has been deprecated.
nowrapThe nowrap attribute disables automatic text wrapping for the cell.

<td> tag example using the nowrap attribute.
<td nowrap="nowrap">$723.48 $1254.58</td>


Note: This attribute has been deprecated.
rowspanThe rowspan attribute specifies how many rows that the cell spans. A value of "1" is the default for this attribute.

HTML & XHTML <td> example using the scope, height, rowspan and valign attributes.
<table border="1">
 <tr>
  <th scope="col">Ticker Symbol</th>
  <th scope="col">Profit</th>
  <th scope="col">Total</th>
 </tr>
 <tr>
  <td scope="row" height="50">MSFT</td>
  <td>$723.48</td>
  <td rowspan="2" valign="middle">$1978.06</td>
 </tr>
 <tr>
  <td scope="row" height="50">GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

scopeThe scope attribute specifies which cells are described by the current cell. Possible values are "col", "colgroup", "row", and "rowgroup". These values are defined as follows: "col" = The current cell provides information about the rest of the column.
"colgroup" = The current cell provides information about the rest of the column group.
"row" = The current cell provides information about the rest of the row.
"rowgroup" = The current cell provides information about the rest of the row group.

HTML & XHTML <td> example using the scope, height, rowspan and valign attributes.
<table border="1">
 <tr>
  <th scope="col">Ticker Symbol</th>
  <th scope="col">Profit</th>
  <th scope="col">Total</th>
 </tr>
 <tr>
  <td scope="row" height="50">MSFT</td>
  <td>$723.48</td>
  <td rowspan="2" valign="middle">$1978.06</td>
 </tr>
 <tr>
  <td scope="row" height="50">GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

valignThe valign attribute specifies the vertical alignment within a cell. Possible values are "baseline", "bottom", "middle", and "top".

HTML & XHTML <td> example using the scope, height, rowspan and valign attributes.
<table border="1">
 <tr>
  <th scope="col">Ticker Symbol</th>
  <th scope="col">Profit</th>
  <th scope="col">Total</th>
 </tr>
 <tr>
  <td scope="row" height="50">MSFT</td>
  <td>$723.48</td>
  <td rowspan="2" valign="middle">$1978.06</td>
 </tr>
 <tr>
  <td scope="row" height="50">GOOG</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style

widthThe width attribute is used to specify the cell width. The value is in pixels, or percentage when followed by a percent sign (%). If the value is specified as a percentage, it refers to a percentage of the available space.

HTML & XHTML <td> example using the width attribute.
<table border="1" width="500">
 <tr>
  <th height="50" colspan="3">Stock Tracker</th>
 </tr>
 <tr>
  <th width="50%">Stock Symbol</th>
  <td width="100">MSFT</td>
  <td>GOOG</td>
 </tr>
 <tr>
  <th height="100">Profit</th>
  <td>$723.48</td>
  <td>$1254.58</td>
 </tr>
</table>
Test It HTML StyleTest It XHTML Style


Note: This attribute has been deprecated.
idThe id attribute assigns a unique name to a tag. This allows style sheets or scripts to reference the tag. See id Example
classThe class attribute assigns a class name to a tag. The class name does not need to be unique. More than one tag can have the same class name. This allows style sheets or scripts to reference multiple tags with a single class name. See class Example
styleThe style attribute specifies styles for the tag. For Cascading Style Sheets (CSS), the syntax is name:value. Each name:value pair is separated by semicolons. See style Example
titleThe title attribute specifies additional information about the tag. It is common for browsers to display the title when the pointing device stops over the object. See title Example
onclickThe onclick attribute specifies a script to be run when the object is clicked with a mouse or other pointing device. See onclick Example
ondblclickThe ondblclick attribute specifies a script to be run when the object is double clicked with a mouse or other pointing device. See ondblclick Example
onkeydownThe onkeydown attribute specifies a script to be run when a key is pressed down. See onkeydown Example
onkeypressThe onkeypress attribute specifies a script to be run when a key is pressed and released. See onkeypress Example
onkeyupThe onkeyup attribute specifies a script to be run when a key is released. See onkeyup Example
onmousedownThe onmousedown attribute specifies a script to be run when the mouse button, or other pointing device button, is pressed while over the object. See onmousedown Example
onmousemoveThe onmousemove attribute specifies a script to be run when the mouse, or other pointing device, is moved while it is over the object. See onmousemove Example
onmouseoutThe onmouseout attribute specifies a script to be run when the mouse, or other pointing device, is moved away from an object after being over it. See onmouseout Example
onmouseoverThe onmouseover attribute specifies a script to be run when the mouse, or other pointing device, is moved onto the object. See onmouseover Example
onmouseupThe onmouseup attribute specifies a script to be run when the mouse button, or other pointing device button, is released while over the object. See onmouseup Example
dirThe dir attribute tells the browser whether the text should be displayed from left-to-right or right-to-left. It does not reverse the direction of the characters, like the <bdo> tag does, but it can help the browser to determine if the text should be aligned on the left side or the right side. See dir Example
langThe lang attribute specifies a language. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See lang Example
xml:langThe xml:lang attribute specifies a language for XHTML documents. This attribute can help the browser to correctly display text. This attribute can also be useful for braille translation software, speech synthesizers, dictionary definitions, etc. See xml:lang Example

Note: XHTML only.

HTML <td> Tag Examples
Test It HTML StyleTest It HTML Style<td> tag example also using the <th> tag for row headers.
Test It HTML StyleTest It HTML Style<td> example using multiple attributes.
Test It HTML StyleTest It HTML Style<td> example using the scope, height, rowspan and valign attributes.
Test It HTML StyleTest It HTML Style<td> example using the width attribute.