HTML <td> Tag

The <td> tag defines a standard data cell in an HTML table. It must be used as a child element of <tr>, which defines a row in a table. To define a header cell the <th> tag is used.

The <td> tag can contain text, form, image, table etc. The content inside it is left-aligned by default.

All the rows in the table contain equal number of cells, which is equivalent to the number of cells in the longest row. If there are less cells in a row, then the browser will automatically fill the row, placing empty cells at the end of it.

If you need to emphasize that there is no data in other cells, then create cell without content where necessary.

The cells added by browser have no borders, and if they go after each other, they will be shown as one integrated cell.

Syntax

<table> 
  <tr> 
    <td>...</td> 
  </tr> 
</table>

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      th, td {
        padding: 10px;
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <table style="width:80%; margin:30px auto; border-collapse:collapse;">
      <tr style="background-color:#1c87c9; color:#fff;">
        <th>Month</th>
        <th>Date</th>
      </tr>
      <tr style="background-color:lightgrey;">
        <td>March</td>
        <td>10.09.2018</td>
      </tr>
      <tr style="background-color:lightgrey;">
        <td>June</td>
        <td>18.07.2018</td>
      </tr>
    </table>
  </body>
</html>

Result

In this example we use <tr> tag to define table rows, <th> to define header cells, and <td> to define standard data cells.

The colspan and rowspan attributes are generally used with <td> tag to let the content span over multiple columns or rows.

Example with colspan attribute

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      th, td { 
        padding: 10px; 
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <table style="width:80%; margin:30px auto; border-collapse:collapse;">
      <tr style="background-color:#1c87c9; color:#fff;">
        <th>Company e-mail</th>
        <th>Date</th>
      </tr>
      <tr>
        <td style="background-color:#e6ebef;"><a href="#">info@w3docs.com</a></td>
        <td style="background-color:#e6ebef;">01.09.2017</td>
      </tr>
      <tr style="height:60px; background-color:#e6ebef;">
        <td colspan="2" valign="bottom"  style="background-color:#a3cced;">info@w3docs.com; <strong>01.09.2017 </strong><span style="font-size:14px;">(received date)</span></td>
      </tr>
    </table>
  </body>
</html>

Result

Example with rowspan attribute

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      th, td { 
        padding: 10px; 
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <table style="width:80%; margin:30px auto; border-collapse:collapse;">
      <tr style="background-color:#1c87c9; color:#fff;">
        <th>Month</th>
        <th>Year</th>
      </tr>
      <tr>
        <td  style="background-color:#e6ebef;">March</td>
        <td rowspan="2" style="background-color:#a3cced; text-align:center;">2014</td>
      </tr>
      <tr style="background-color:#e6ebef;">
        <td style="background-color:#e6ebef;">April</td>
      </tr>
    </table>
  </body>
</html>

Result

Attributes

Attribute Value Description
abbr text Defines an abbreviated version of the content in a cell, or an alternative text. (User-agents, such as speech readers, may present this description before the content itself).
Not supported in HTML 5.
align left
right
center
justify
char
Aligns the content in a cell.
Not supported in HTML 5.
axis category_name Categorizes cells having similar content.
Not supported in HTML 5.
background background Sets the background in a cell.
Not supported in HTML 5.
bgcolor rgb(x,x,x)
#xxxxxx
colorname
Defines the background color of a cell.
Not supported in HTML 5.
bordercolor bordercolor Sets the color of the border.
Not supported in HTML 5.
char character Aligns the content in a cell to a character. Is used only if attribute align = "char".
Not supported in HTML 5.
charoff number Sets the number of characters the content will be aligned from the character specified by the char attribute. Is used only if attribute align = "char".
Not supported in HTML 5.
colspan number Defines the number of columns a cell should span. The value of the attribute should be a positive integer. Default value is 1.
headers header_id Specifies one or more header cells (defined by the <th> tag) a standard cell is related to.
height %
pixels
Sets the height of a cell.
Not supported in HTML 5.
nowrap nowrap Specifies that the content inside a cell should not wrap.
Not supported in HTML 5.
rowspan number Specifies the number of rows a cell should span. The value of the attribute should be a positive integer. Default value is 1. It is not recommended to use values higher than 65534, as they will be clipped down to 65534.
scope col
colgroup
row
rowgroup
Defines the cells that the header (defined in the <th>) element relates to.
Not supported in HTML 5.
valign top
middle
bottom
baseline
Specifies vertical alignment of the content inside a cell.
Not supported in HTML 5.
width %
pixels
Sets the width of a cell.
Not supported in HTML 5.

The <td> tag supports the Global Attributes and the Event Attributes.

Browser support