Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML td tag

Bypass main content

HTML td tag

Note: If you don't know what an element/tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.

Bypass main content

Description

The HTML td element inserts a data cell in a table (HTML table element).

There can be two types of cells in a table: a data cell and a header cell (HTML th element). Header cells are supposed to provide header information for data cells, but there are cases when data cells can also provide header in formation. This can be achieved by using the "headers" and "scope" attributes in (or pointing to) data cells.

Note that the attributes "width", "height", "nowrap" and "bgcolor" have been deprecated in HTML 4.01 because of their presentational nature. Therefore, their use is no longer recommended.

Examples

Code
<table>
<thead>
<tr>
<th>User</th>
<th>Points</th>
<th>Active</th>
</tr>
</thead>
<tbody>
<tr>
<td>sammy</td>
<td>248</td>
<td>Yes</td>
</tr>
<tr>
<td>jhon45</td>
<td>146</td>
<td>Yes</td>
</tr>
</tbody>
<tbody>
<tr>
<td>ackbard</td>
<td>801</td>
<td>No</td>
</tr>
<tr>
<td>jacks34</td>
<td>248</td>
<td>No</td>
</tr>
</tbody>
</table>
View
User Points Active
sammy 248 Yes
jhon45 146 Yes
ackbard 801 No
jacks34 248 No

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).

<p id="paragraph1">This is the first paragraph, named "paragraph1". To dynamically change its properties use this identifier.</p>

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used together with style sheets and tells the browser the class (or classes) to which the element is associated with.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although, in some cases, it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style.</p>
<p>And this is another text without style.</p>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a small period of time.

Code
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
View

lang (langcode)

Specifies the language of an element's content. The default value in "unknown".

When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously like in the example below. Note, that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.

<p lang="en" xml:lang="en">This is a paragraph in english.</p>
<p lang="es" xml:lang="es">Este es un párrafo en español.</p>

dir

This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:

  • RTL: Right to left.
  • LTR: Left to right.
<q lang="he" dir="rtl">...an Hebrew quotation...</q>

colspan (number)

Specifies the number of columns to be spanned by this cell. The default value is "1".

The value "0" means that this cells will span all cells in the row, from it's position to the last column of the container section (HTML colgroup element).

Code
<table>
<tr>
<td rowspan="2">Cell1</td>
<td>Cell2</td>
</tr>
<tr>
<td>Cell3</td>
</tr>
</table>
View
Cell1 Cell2
Cell3

rowspan (number)

Specifies the number of rows to be spanned by this cell. The default value is "1".

The value "0" means that this cells will span all cells in the column, from it's position to the last row of the container section (HTML thead element, HTML tbody element or HTML tfoot element).

Code
<table>
<tr>
<td>Cell1</td>
<td>Cell2</td>
</tr>
<tr>
<td colspan="2">Cell3</td>
</tr>
</table>
View
Cell1 Cell2
Cell3

headers (idref)

Contains a space-separated list of ids corresponding to other cells that provide header information for the current one.

<td headers="united-states production">15,434</td>

scope

Specifies a group of cells for which the current will provide header information. Possible values (case-insensitive) are:

<th scope="colgroup">Production</th>

axis (cdata)

This attribute provides a list of comma-separated category names to which the current cell belongs. These conceptual categories can form groups of cells that show data related under some point of view.

User agents may use the information in this attribute to provide some functionality to display and relate these categories.

<td axis="Total production,Goods,Sales">1,154</td>

abbr (text)

Provides a shorter alternative to the cell's content, that may be used by browsers when appropriate. A good use for this attribute could be to replace the cell's content when the rendering space is reduced.

<td abbr="Income">Income from goods and services</td>

align

Defines how the text of inside the cell is horizontally aligned. It has five possible case-insensitive values:

  • left: The text is aligned to the left. This is the default value for common cells (HTML td tag).
  • center: The text is centered. This is the default value for table headers (HTML th tag).
  • right: The text is aligned to the right.
  • justify: The data is justified to both, left and right, margins.
  • char: The text is aligned around a specific character, set in the "char" attribute.
<td align="center">Content</td>

valign

Defines how the text inside the cell is vertically aligned. Its possible case-insensitive values are:

  • top: The text is aligned to the top.
  • middle: The text is vertically centered. This is the default value.
  • bottom: The text is aligned to the botom.
  • baseline: All the cells in a row that has this alignment should have their first text line on a common baseline.
<td valign="top">Content</td>

char (character)

Indicates a single character that acts as alignment axis for the text inside the cell. The default value is the decimal point character for the current language.

Note that browsers aren't required to support this feature, so the compatibility using this attribute could be reduced.

<td align="char" char=".">1.12</td>

charoff (length)

Specifies the offset to the first occurrence of the alignment character on each line, considering the text direction.

Note that browsers aren't required to support this feature, so the compatibility using this attribute could be reduced.

<td align="char" char="." charoff="1">1.12-11.24</td>

width (length)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

Provides a recommended height for the cell. Browsers may change this value depending on space availability.

<td width="50">Content</td>

height (length)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

Provides a recommended height for the cell.

<td width="20">Content</td>

nowrap

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

When this boolean attribute is present, user agents disable automatic text wrapping for the content of the cell.

Remember that in XHTML, boolean attributes must take their own names as value (e.g., attr_name="attr_name").

<td nowrap="nowrap">This text will be shown in a single line.</td>

bgcolor (color)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

Defines the color that will be used as background of the cell.

<td bgcolor="green">Content</td>

Events

  • onclick
  • ondblclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmousemove
  • onmouseout
  • onkeypress
  • onkeydown
  • onkeyup

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate