HTML table cell - how to use <td> tag

The HTML <td> tag is used to define a standard table cell. A header cell can be created using <th> tag.

Text is left aligned by default for <td> tag and center aligned and bold for <th> tag.

Attributes

The td tag supports the global and event attributes.

colspan
Defines the number of columns a table cell should span
headers
Defines the header cells this cell related to
rowspan
Defines the number of rows a table cell should span

Examples:

<table border="1"> <thead> <tr> <th>Country</th> <th>Capital</th> <th>City</th> </tr> </thead> <tbody> <tr> <td>China</td> <td>Beijing</td> <td>Shanghai</td> </tr> <tr> <td>India</td> <td>New Delhi</td> <td>Hyderabad</td> </tr> </tbody> <tfoot> <tr> <td>Table</td> <td>Ends</td> <td>Here</td></tr> </tfoot> </table>

Related HTML tags and Useful Links:

  • <table> - used to define a table
  • <thead> - used to define header of the table
  • <tbody> - used to define the table body
  • <tfoot> - used to define footer of the table
  • <th> - used to define header cells
  • <tr> - used to define table row
  • <td> - used to define the cell of the table
  • <caption> - used to define caption / title of the table
  • <col> - used to define properties of columns defined within the <colgroup> tag
  • <colgroup> - used to group one or more columns
  • Learn more about HTML table