HTML <td> Tag

Beginner
6 min read
Updated: Nov 2026
4 examples
Live preview

Definition and Usage

The <td> element defines a table data cell. It must be a child of <tr> inside a <table>. Use it for values in the grid. For column or row labels, use <th> instead.

Span cells with colspan and rowspan. In complex tables, link a cell to its headers with headers. Prefer simple tables when you can.

Baseline · Widely available.

Not deprecated. Core td support has been stable across browsers since about July 2015 (and much earlier in practice).

Deprecated attributes.

Do not use abbr, align, axis, bgcolor, char, charoff, height, scope, valign, or width on <td>. Prefer CSS, and use scope only on <th>.

HTML Syntax

syntax.html
<td> cell content</td>

The start tag is required. The end tag may be omitted in some cases, but writing both tags is clearer. Content can be flow content (text, paragraphs, lists, and more).

Attributes

The attributes you will use most often on <td>:

AttributeDescriptionTry it
colspanHow many columns the cell spans (default 1; max effectively 1000)Try it
rowspanHow many rows the cell spans (default 1; 0 means through the end of the row group)Try it
headersSpace-separated id list of related <th> cellsTry it
bgcolorDeprecated — use CSS background-color insteadTry it

Also deprecated (do not use on new pages): align, valign, width, height, axis, and scope (valid on th only).

Global Attributes

The <td> tag also supports the Global Attributes in HTML.

Live Preview

Change a data cell’s text and colspan on a real table.

The highlighted cell is a real <td>. With colspan="2" it covers Open and Close.

Table
Store hours
DayOpenClose
Mon–Fri9:0018:00
WeekendClosed

colspan="2" — Closed

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Basic Data Cells

Put values in <td> and labels in <th>.

HTML
<table>
  <tr>
    <th scope="col">Player</th>
    <th scope="col">Score</th>
  </tr>
  <tr>
    <th scope="row">Ada</th>
    <td>92</td>
  </tr>
  <tr>
    <th scope="row">Grace</th>
    <td>88</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Each row is a <tr>. Cells sit inside that row.
  2. Use <th> for Player / Score labels and row names.
  3. Use <td> for the numeric scores.
  4. Keep columns aligned so every row has the same cell count (unless you span).

Example 2 — colspan

Let one data cell cover two columns.

HTML
<table>
  <caption>Store hours</caption>
  <tr>
    <th scope="col">Day</th>
    <th scope="col">Open</th>
    <th scope="col">Close</th>
  </tr>
  <tr>
    <td>Mon–Fri</td>
    <td>9:00</td>
    <td>18:00</td>
  </tr>
  <tr>
    <td>Weekend</td>
    <td colspan="2">Closed</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Count columns from the header (Day, Open, Close = 3).
  2. Set colspan="2" so one cell covers Open and Close.
  3. Check the math: Day (1) + spanned cell (2) = 3.
  4. Do not overlap cells with conflicting spans.

Example 3 — rowspan

Let one data cell stretch down across two rows.

HTML
<table>
  <caption>Team shifts</caption>
  <tr>
    <th scope="col">Name</th>
    <th scope="col">Shift</th>
    <th scope="col">Desk</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>Morning</td>
    <td rowspan="2">A1</td>
  </tr>
  <tr>
    <td>Grace</td>
    <td>Afternoon</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Put rowspan="2" on the Desk cell in the first data row.
  2. Omit that column in the next row — the span fills it.
  3. rowspan="0" (advanced) extends to the end of the current row group.
  4. Keep spans simple; heavy grids are harder for screen readers.

Example 4 — headers Attribute

Point a complex cell at related <th> ids when scope alone is not enough.

HTML
<table>
  <tr>
    <th id="am" scope="row">AM</th>
    <td>Open</td>
    <td headers="am pm" rowspan="2">Shared desk</td>
  </tr>
  <tr>
    <th id="pm" scope="row">PM</th>
    <td>Open</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Give each related th a unique id.
  2. On the data cell, set headers="id1 id2" (space-separated).
  3. Assistive tech can announce those headers with the cell.
  4. Prefer simpler tables first; use headers when the grid is irregular.

Edge Cases & Pitfalls

Most td mistakes are wrong cell type, broken spans, or presentational attributes.

semantics

Do not fake headers with bold td

Labels belong in <th>. Styling a td as bold does not make it a header for assistive tech.

spans

Never overlap cells

colspan / rowspan must leave a valid grid. Overlaps are invalid and render unpredictably.

scope

scope is not for td

On data cells, scope is deprecated. Use it on <th>, or use headers for complex links.

attrs

Skip width / align / bgcolor

Style cells with CSS. Presentational HTML attributes on td are obsolete.

parent

Only inside tr

<td> is invalid outside a table row. Always nest it under <tr>.

Browser Support

The <td> element is core HTML table markup in every browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

<td>

Widely available since about July 2015 (and long before). colspan, rowspan, and headers are broadly supported; presentational attributes are obsolete.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported
<td> Widely supported

Bottom line: Safe to use everywhere for data cells. Prefer th for headers, keep spans simple, and style with CSS.

Key Takeaways

  • Role: <td> holds data values inside a <tr>.
  • vs th: labels → th; values → td.
  • Spans: colspan / rowspan merge cells without overlapping.
  • Complex a11y: use headers + id when needed.

One line: put each data value in a <td>, keep headers in <th>, and span cells only when the math stays valid.

Default CSS Settings

Typical user-agent styling for td (simplified; exact rules vary by browser):

default.css
td {
  display: table-cell;
  vertical-align: inherit;
  unicode-bidi: isolate;
  padding: 1px;
}

Learners often add borders and padding on th, td, and set border-collapse: collapse on the table.

Frequently Asked Questions

The td element is a table data cell. Put it inside a tr to hold a value that belongs in the grid — not a column or row label (use th for those).
td is a normal data cell. th is a header cell for a column or row. Screen readers treat th as a heading for related cells.
colspan makes a cell cover extra columns; rowspan covers extra rows. Default for both is 1. Do not overlap cells with these attributes.
In complex tables where scope alone is not enough, give each th an id and list those ids in headers on the related td cells.
No. td is only valid as a child of tr (inside a table).
No. Those attributes are deprecated. Style cells with CSS such as width, text-align, and background-color.

Next: template

Hold inert HTML fragments for cloning with JavaScript.

template tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful