<td> represents a data cell inside a tr. A cell may contain text, links, controls, or other flow content. Use th when a cell labels a row or column.
Data with headers
Here, the counts are data cells; the workshop names and column titles are header cells. The class changes numeric alignment without changing the cells’ meaning.
HTML and CSS
HTML
<table>
<caption>
Workshop registrations
</caption>
<thead>
<tr>
<th scope="col">Workshop</th>
<th scope="col">Places booked</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">HTML basics</th>
<td class="amount">12</td>
</tr>
<tr>
<th scope="row">CSS layout</th>
<td class="amount">8</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">Total</th>
<td class="amount">20</td>
</tr>
</tfoot>
</table>
CSS
/* Presentation: these styles make the table easier to read. */
table {
border-collapse: collapse;
}
caption {
text-align: left;
font-weight: bold;
margin-bottom: 0.5rem;
}
th,
td {
border: 1px solid #94a3b8;
padding: 0.5rem 0.75rem;
text-align: left;
}
.amount {
text-align: right;
font-variant-numeric: tabular-nums;
}
Edit HTML or CSS to update the preview as you type. Copy code snippet copies the selected tab. Preview spacing and font defaults are not included.
Spanning and associations
colspan defaults to 1 and can span up to 1000 columns. rowspan defaults to 1; rowspan="0" extends through the remaining rows in the same row group. Spans must fit the table without overlapping cells.
For a simple table, clear row and column header structure is usually enough. For a complex table, a data cell’s headers attribute can list the space-separated IDs of its applicable <th> cells.
Try a change
Add a third column named “Location,” then add a data cell to every corresponding row. If the total row should not report a location, give its label colspan="2" only after reordering columns so that the label spans the intended positions. Do not use empty cells merely to create page spacing.
A <td> written outside a table row is invalid; HTML error recovery may move or drop it. Keep the whole table when copying the example.
Sources and browser support
MDN: td describes the syntax and links to the specification and compatibility data. Check individual values in that table when supporting older browsers.