<td> Tag in HTML | Table Data Cell
The <td> tag is used to define a cell in a table that holds data. It is placed within the <tr> (table row) tag and represents individual data within the table. The <td>
tag can hold text, images, links, or other HTML elements.
Key Points on <td> Tag:
- The <td> tag is used to define a data cell in a table.
- Each
<td>
element is placed inside a<tr>
(table row) to form the table structure. - It is commonly used in combination with the <th> tag, which defines header cells in a table.
- The content inside a
<td>
can be text, images, form elements, or even other tables. - Attributes like
colspan
androwspan
can be used to extend a cell across multiple columns or rows.
Syntax of <td> Tag:
Syntax Example
<tr>
<td>Data in Cell</td>
</tr>
Example of <td> Tag in HTML:
This example demonstrates how to use the <td>
tag to create a table with two columns.
Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Data Example</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John Doe</td>
<td>30</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
</tr>
</table>
</body>
</html>
Output
Name | Age |
---|---|
John Doe | 30 |
Jane Smith | 25 |
Attributes of <td> Tag:
- colspan: Specifies the number of columns a cell should span.
- rowspan: Specifies the number of rows a cell should span.
- align: Specifies the horizontal alignment of the content (left, right, center).
- valign: Specifies the vertical alignment of the content (top, middle, bottom).
The <td>
tag is essential for displaying data in a table. It allows for organized representation of information and can be customized with various attributes to control the layout and appearance of the table.