<td>
A regular table cell with data.
- Display
- table-cell
- Closing tag
- Required
- Permitted content
- Flow content
Example
#<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #8886; padding: 4px 10px; }
</style>
<table>
<tr>
<th scope="col">Time</th>
<th scope="col">Monday</th>
<th scope="col">Tuesday</th>
</tr>
<tr>
<th scope="row">4:00 PM</th>
<td rowspan="2">HTML workshop</td>
<td>CSS quiz</td>
</tr>
<tr>
<th scope="row">5:00 PM</th>
<td>Office hours</td>
</tr>
<tr>
<th scope="row">6:00 PM</th>
<td colspan="2">Group coding online</td>
</tr>
</table>Definition and usage
#The <td> element (from table data) is a data cell. It sits inside a <tr> row and can contain any flow content: text, numbers, links, images, or even a list or a button.
A cell can span several columns (colspan) or rows (rowspan). Remember that in the following rows you then skip the cells in the places taken by the spanning one.
Text in cells is by default aligned to the start of the row and vertically centered. You can change both settings in CSS with the text-align and vertical-align properties.
Syntax
#<td>data</td>Attributes
#positive number (default 1)
The number of columns the cell spans. In a row with such a cell you write correspondingly fewer<td>elements.non-negative number (default 1)
The number of rows the cell spans. In the following rows you skip the cell in this column, because its place is already taken.list of ids
The ids of the<th>cells that describe this cell, separated by spaces. It’s used in complex tables wherescopeisn’t enough, for example when the headers have several levels.
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#colspan
positive number (default 1)The number of columns the cell spans. In a row with such a cell you write correspondingly fewer <td> elements.
<style>
table { border-collapse: collapse; }
td { border: 1px solid #8886; padding: 4px 10px; text-align: center; }
</style>
<table>
<tr><td>HTML</td><td>CSS</td><td>JavaScript</td></tr>
<tr><td colspan="3">All three courses in one bundle</td></tr>
</table>rowspan
non-negative number (default 1)The number of rows the cell spans. In the following rows you skip the cell in this column, because its place is already taken.
<style>
table { border-collapse: collapse; }
td { border: 1px solid #8886; padding: 4px 10px; }
</style>
<table>
<tr><td rowspan="2">Week 1</td><td>Page structure</td></tr>
<tr><td>Text and links</td></tr>
<tr><td>Week 2</td><td>Images</td></tr>
</table>headers
list of idsThe ids of the <th> cells that describe this cell, separated by spaces. It’s used in complex tables where scope isn’t enough, for example when the headers have several levels.
<style>
table { border-collapse: collapse; }
th, td { border: 1px solid #8886; padding: 4px 10px; }
</style>
<table>
<tr>
<td></td>
<th id="quiz1">Quiz 1</th>
<th id="quiz2">Quiz 2</th>
</tr>
<tr>
<th id="ola">Ola</th>
<td headers="ola quiz1">9/10</td>
<td headers="ola quiz2">10/10</td>
</tr>
</table>Default CSS
#Most browsers display this element with these default styles:
td {
display: table-cell;
padding: 1px;
vertical-align: inherit;
}Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Leave an empty cell as
<td></td>, but don’t remove it from the row. Missing cells break the column layout. - Amounts and numbers are easier to compare when right-aligned:
td.amount { text-align: right; }.font-variant-numeric: tabular-numsalso helps, as it gives all digits equal width.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.