HTML Reference ยท Tables
The <td> element
Reference for the HTML <td> element: table data cells, the colspan, rowspan and headers attributes, accessibility notes, CSS replacements and technical details.
The <td> element is a data cell in a table. It sits inside a <tr> and holds one value: a number, a word, a link, or any other flow content such as a list or an image. Cells that label other cells should use <th> instead.
A cell can stretch across several columns with colspan or several rows with rowspan.
<tr> <td>Oat milk</td> <td colspan="2">Out of stock</td> </tr>
Try it
The youth squad cell covers two rows with rowspan="2", so the 18:00 row needs only one <td>. The cleaning notice spans both wall columns with colspan="2".
Attributes
| Attribute | Values | Description |
|---|---|---|
colspan |
A positive integer (1โ1000) | The number of columns the cell covers. Defaults to 1. |
rowspan |
A non-negative integer (0โ65534) | The number of rows the cell covers. Defaults to 1. The value 0 stretches the cell to the end of its row group (<thead>, <tbody> or <tfoot>). |
headers |
Space-separated list of ids |
The ids of the <th> cells that label this cell. Use it in complex tables where scope is not enough. |
It also accepts the global attributes. The obsolete align, valign, width, height, bgcolor, nowrap, abbr, axis and scope attributes on <td> should be replaced with CSS (text-align, vertical-align, width, background-color, white-space: nowrap) or, for header-related ones, with a <th>.
Usage notes
- Count your cells. After spans, every row should cover the same number of columns. A row that comes up short leaves an empty gap; one that is too long adds a new column.
- Linking cells to headers. In simple tables, screen readers work out each cell's headers from
<th>andscope. When headers sit at several levels, list them on the cell:<td headers="q2 north">. - Empty cells. An empty
<td>is fine when there is no value, but a dash or "n/a" tells readers the gap is intentional. - Cells are not layout boxes. Don't use cells to position page sections. Use CSS grid or flexbox, and keep
<td>for data. - Role in grids. If the table has
role="grid"orrole="treegrid", a<td>is exposed as agridcell.
Technical summary
| Content categories | None |
| Permitted content | Flow content |
| Tag omission | The start tag is required. The end tag can be omitted if the cell is immediately followed by a <td> or <th>, or if there is no more content in the parent element |
| Permitted parents | A <tr> element |
| Implicit ARIA role | cell when the table is exposed as a table; gridcell when it is a grid or treegrid |
| DOM interface | HTMLTableCellElement |
| Default display | table-cell |
Browser support
Supported in every browser. rowspan="0" is supported in current versions of the major browsers.
Related
<th>โ header cells<tr>โ the row that holds the cell<table>โ the table itself- Lesson: Tables
- Lesson: Spanning Rows and Columns
- Lesson: Accessible Tables