HTML td tag
Example
A simple HTML table, with two rows and four table cells:
<tr>
<td>Cell A</td>
<td>Cell B</td>
</tr>
<tr>
<td>Cell C</td>
<td>Cell D</td>
</tr>
</table>
Definition and Usage
The <td>
tag defines a standard data cell in an HTML table.
An HTML table has two kinds of cells:
- Header cells - contains header information (created with the <th> element)
- Data cells - contains data (created with the
<td>
element)
The text in <td>
elements are regular and left-aligned by default.
The text in <th> elements are bold and centered by default.
Browser Support
Element | |||||
---|---|---|---|---|---|
<td> | Yes | Yes | Yes | Yes | Yes |
Attributes
Attribute | Value | Description |
---|---|---|
colspan | number | Specifies the number of columns a cell should span |
headers | header_id | Specifies one or more header cells a cell is related to |
rowspan | number | Sets the number of rows a cell should span |
Global Attributes
The <td>
tag also supports the Global Attributes in HTML.
Event Attributes
The <td>
tag also supports the Event Attributes in HTML.
More Examples
Example
How to align content inside <td> (with CSS):
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td style="text-align:right">Rs.100</td>
</tr>
<tr>
<td>February</td>
<td style="text-align:right">Rs.80</td>
</tr>
</table>
Example
How to add background-color to table cell (with CSS):
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="background-color:#FF0000">January</td>
<td style="background-color:#00FF00">Rs.100</td>
</tr>
</table>
Example
How to set the height of a table cell (with CSS):
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="height:100px">January</td>
<td style="height:100px">Rs.100</td>
</tr>
</table>
Example
How to specify no word-wrapping in table cell (with CSS):
<tr>
<th>Poem</th>
</tr>
<tr>
<td style="white-space:nowrap">Never increase, beyond what is necessary, the number of entities required to explain anything</td>
</tr>
</table>
Example
How to vertical align content inside <td> (with CSS):
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr style="height:100px">
<td style="vertical-align:bottom">January</td>
<td style="vertical-align:bottom">Rs.100</td>
</tr>
</table>
Example
How to set the width of a table cell (with CSS):
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td style="width:70%">January</td>
<td style="width:30%">Rs.100</td>
</tr>
</table>
Example
How to create table headers:
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>SamS</td>
<td>sam.s@lovelife.com</td>
<td>123-45-678</td>
</tr>
</table>
Example
How to create a table with a caption:
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>Rs.100</td>
</tr>
<tr>
<td>February</td>
<td>Rs.80</td>
</tr>
</table>
Example
How to define table cells that span more than one row or one column:
<tr>
<th>Name</th>
<th>Email</th>
<th colspan="2">Phone</th>
</tr>
<tr>
<td>SamS</td>
<td>sam.s@lovelife.com</td>
<td>123-45-678</td>
<td>212-00-546</td>
</tr>
</table>
Default CSS Settings
Most browsers will display the <td>
element with the following default values:
display: table-cell;
vertical-align: inherit;
}
Comments
Post a Comment