HTML <td> Tag โ Table Data Cell
๐ Introduction
The <td> tag defines a data cell in an HTML table.
It is used to store the actual content inside a table row.
๐ It always works inside a <tr> (table row).
๐งฑ Syntax
<table>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>TD Example</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>yourName</td>
<td>20</td>
<td>Algeria</td>
</tr>
<tr>
<td>Sara</td>
<td>22</td>
<td>Morocco</td>
</tr>
</table>
</body>
</html>
๐ฅ๏ธ Output Explanation
<td>contains the actual table data- Each
<tr>row contains multiple<td>cells - Data is displayed in columns
๐ฏ Why <td> is Important
1. ๐ Stores Table Data
Everything inside a table (except headers) uses <td>.
2. ๐งฑ Builds Rows
Each row is made of multiple <td> elements.
3. โ๏ธ Works with All Table Sections
Used inside:
<thead><tbody><tfoot>
๐งฉ Example Structure
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>yourName</td>
<td>20</td>
</tr>
</table>
โ๏ธ <td> vs <th>
| Tag | Purpose | Style |
|---|---|---|
<td> |
Data cell | Normal text |
<th> |
Header cell | Bold + centered |
๐ฏ Advanced Usage
Merging Columns
<tr>
<td colspan="2">Merged Cell</td>
</tr>
โ Combines multiple columns
Merging Rows
<tr>
<td rowspan="2">Merged Row</td>
<td>Data</td>
</tr>
โ Combines multiple rows
๐จ Styling Example
<td style="padding:10px; background:#f9f9f9;">yourName</td>
๐ซ Common Mistakes
- Using
<td>outside<tr>โ - Confusing
<td>with<th>โ - Missing table structure โ
๐งช Mini Exercise
Create a table with:
- 3 columns (Name, Age, City)
- At least 3 rows using
<td> - Add borders
- Try using
colspanin one row