HTML Tutorial

HTML Tag: <td>

Usage of <td>:

The <td> (table data) tag defines a cell in an HTML table. It contains the actual data displayed in the table.

Attributes of <td>:

  • align: Specifies the horizontal alignment of the cell content (left, center, right)
  • width: Defines the width of the cell
  • height: Sets the height of the cell

Examples with <td>:

<tr>
  <td>Name</td>
  <td>John</td>
</tr>
<tr>
  <td>Age</td>
  <td>30</td>
</tr>

This code creates a table with two rows and two columns:

╔══════╦══════╗
║ Name ║ John ║
╠══════╬══════╣
║ Age  ║ 30   ║
╚══════╩══════╝

Exploring the <td> Tag:

Practical Example:

<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>John</td>
    <td>30</td>
  </tr>
  <tr>
    <td>Mary</td>
    <td>25</td>
  </tr>
</table>

This code creates a simple HTML table with data. The <th> tags represent the table headers, while the tags contain the data.

Accessibility and Ease of Use:

  • Use the aria-labelledby attribute to associate the <td> with its header
  • Provide a <th> for each <td> to improve accessibility for screen readers
  • Use CSS styles to improve the appearance and readability of the table