HTML <table> Tag

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

Definition and Usage

The <table> element represents tabular data — information in a two-dimensional grid of rows and columns. Each row is a <tr>; cells are <th> (headers) or <td> (data).

Optionally add a <caption>, group columns with <colgroup> / <col>, and group rows with <thead>, <tbody>, and <tfoot>. Style appearance with CSS — not obsolete HTML attributes.

Baseline · Widely available.

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

Deprecated attributes.

Do not use align, bgcolor, border, cellpadding, cellspacing, frame, rules, summary, or width on <table>. Prefer CSS and a <caption> instead.

Non-standard.

Some browsers historically accepted a non-standard height on <table>. Use CSS min-height (or height) instead.

HTML Syntax

syntax.html
<table> rows & cells</table>

Both start and end tags are required. Put an optional <caption> first, then optional column groups, then header/body/footer row groups (or plain <tr> rows).

Attributes

Modern <table> has no current element-specific attributes — only global attributes. These older attributes are deprecated (shown for migration):

AttributeDescriptionTry it
borderDeprecated — use CSS border insteadTry it
cellpaddingDeprecated — use CSS padding on cells insteadTry it
cellspacingDeprecated — use CSS border-spacing insteadTry it
widthDeprecated — use CSS width insteadTry it
alignDeprecated — use CSS margins / alignment insteadTry it
bgcolorDeprecated — use CSS background-color insteadTry it
summaryDeprecated — use a <caption> insteadTry it
rules / frameDeprecated — use CSS borders on table parts insteadTry it

On cells, learn scope, colspan, rowspan, and headers — they belong on <th> / <td>, not on <table>.

Global Attributes

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

Live Preview

Switch sample datasets and optionally show a caption on a real <table>.

A real <table> with <th> headers. Caption is the first child when shown.

Table
Team members
NameRole
AlexDesigner
SamDeveloper

<table> with caption and two columns

HTML Examples

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

Example 1 — Basic Table

Build a small data grid with header cells and data cells.

HTML
<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>36</td>
  </tr>
  <tr>
    <td>Grace</td>
    <td>41</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Open <table>. It is the container for the grid.
  2. Add a row with <tr>. Put column labels in <th>.
  3. Add data rows. Each value goes in a <td>.
  4. Keep columns aligned. Every row should have the same number of cells (unless you intentionally span).

Example 2 — Caption, thead, tbody, tfoot

Name the table, group the header and body, and put a summary row in the footer.

HTML
<table>
  <caption>Front-end course scores</caption>
  <thead>
    <tr>
      <th scope="col">Student</th>
      <th scope="col">Score</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Chris</td>
      <td>88</td>
    </tr>
    <tr>
      <td>Dana</td>
      <td>92</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th scope="row">Average</th>
      <td>90</td>
    </tr>
  </tfoot>
</table>
Try It Yourself

How It Works

  1. Put <caption> first so users (and assistive tech) get a short title.
  2. Wrap header rows in <thead> and data rows in <tbody>.
  3. Use <tfoot> for totals or notes that belong with the table.
  4. Order in HTML is typically caption → thead → tbody → tfoot (browsers still render the footer at the bottom).

Example 3 — scope on Headers

Tell assistive technology whether a <th> labels a column or a row.

HTML
<table>
  <caption>Weekly hours</caption>
  <tr>
    <th scope="col">Person</th>
    <th scope="col">Mon</th>
    <th scope="col">Tue</th>
  </tr>
  <tr>
    <th scope="row">Alex</th>
    <td>4</td>
    <td>6</td>
  </tr>
  <tr>
    <th scope="row">Sam</th>
    <td>5</td>
    <td>5</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. scope="col" marks a header for the whole column.
  2. scope="row" marks a header for that row (often the first cell).
  3. Simple tables can often infer scope, but setting it is a clear habit.
  4. Complex grids with multi-level headers may need id + headers instead.

Example 4 — Merge Cells with colspan

Let one cell span across two columns. Prefer simple tables when you can.

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 row (here: Day, Open, Close = 3).
  2. Set colspan="2" so one cell covers Open and Close.
  3. Keep the math right: Day (1) + spanned cell (2) = 3 columns.
  4. Use sparingly. Heavy spanning is harder for screen readers; split into smaller tables when possible.

Edge Cases & Pitfalls

Most table problems come from layout misuse, missing headers, or over-complex spans.

layout

Do not use tables for page layout

Tables describe data relationships. Page structure belongs to CSS Grid or Flexbox.

a11y

Always mark real headers

Bold text in a <td> is not a header. Use <th> (and scope when helpful).

attrs

Skip obsolete presentational attributes

border, cellpadding, and friends are deprecated. Use CSS such as border-collapse.

complexity

Prefer several simple tables

Heavy colspan/rowspan grids are hard to navigate. Split data or use headers/id only when you must keep one complex table.

mobile

Wide tables need overflow plans

Wrap the table in a scrollable container or redesign for small screens so content stays readable.

Browser Support

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

✓ Baseline · Widely available

<table>

Widely available since about July 2015 (and long before as HTML tables). Chrome, Firefox, Safari, Edge, and Opera all support tabular markup fully. Presentational attributes are obsolete; use CSS instead.

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
<table> Widely supported

Bottom line: Safe to use everywhere for tabular data. Style with CSS, provide captions and headers, and avoid layout tables.

Key Takeaways

  • Role: <table> is for tabular data — not page layout.
  • Structure: rows with tr; labels with th; values with td.
  • Clarity: add caption, and use thead/tbody/tfoot when sections help.
  • Style: CSS only — skip deprecated presentational attributes.

One line: put real data in a <table> with <th> headers (and a caption when it needs a name).

Default CSS Settings

Typical user-agent styling for tables (simplified). Exact rules vary by browser:

default.css
table {
  display: table;
  border-collapse: separate;
  border-spacing: 2px;
  box-sizing: border-box;
  text-indent: 0;
}

caption {
  display: table-caption;
  text-align: center;
}

thead {
  display: table-header-group;
  vertical-align: middle;
}

tbody {
  display: table-row-group;
  vertical-align: middle;
}

tfoot {
  display: table-footer-group;
  vertical-align: middle;
}

tr {
  display: table-row;
  vertical-align: inherit;
}

th,
td {
  display: table-cell;
  vertical-align: inherit;
  padding: 1px;
}

th {
  font-weight: bold;
  text-align: center;
}

Learners often set border-collapse: collapse and add borders/padding so cells look connected.

Frequently Asked Questions

The table element presents tabular data in rows and columns. Use it for information that belongs in a grid (schedules, comparisons, records) — not for page layout.
th is a header cell for a column or row label. td is a normal data cell. Screen readers treat th as a heading for related cells.
Not for every table. A simple table can use only table, tr, th, and td. Use thead, tbody, and tfoot when you want a clear header, body, and footer (for example totals).
No. Those attributes are deprecated. Style tables with CSS — for example border-collapse, border, padding, and border-spacing.
Add a caption that names the table, use th for headers, and set scope="col" or scope="row" when it helps. Prefer simple tables over heavy colspan and rowspan.
No. Tables are for tabular data only. Use CSS Grid or Flexbox to arrange page sections.

Next: tbody

Group the main data rows of a table inside the table body.

tbody 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