HTML <td>
Tag
The <td>
tag in HTML is used to define a cell in a table. It stands for table data, and is used to hold data within rows and columns in a table.
Usage of the <td>
tag:
In a table structure, each row is made up of multiple cells, defined by the <td> tag. These cells are then arranged in columns. The <td> tag holds the actual content of the cell.
Main tag attributes of the <td>
tag:
Attribute | Description |
---|---|
colspan |
Specifies how many columns a cell should span |
rowspan |
Specifies how many rows a cell should span |
headers |
Specifies one or more header cells a cell is related to |
Examples of using the <td>
tag:
Here is an example of a table with multiple cells defined by the <td>
tag:
<table>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</table>
In the above example, each row contains two cells defined by the <td> tag.
Here is an example of using the colspan
attribute to span a cell across multiple columns:
<table>
<tr>
<td colspan="2">Spanning two columns</td>
<td>Cell 3</td>
</tr>
</table>
In the above example, the first cell spans across two columns using the colspan
attribute.
Conclusion:
The <td>
tag is an essential part of creating tables in HTML. It allows you to define individual cells within a table and add content to those cells. By using attributes like colspan
and rowspan
, you can control the layout and structure of your table effectively.