<table> Tag in HTML

Quick facts

CategoryFlow content
Content modelOptional <caption>, then rows grouped via <thead>, <tbody>, and <tfoot>, each containing <tr> rows of <td>/<th> cells
Tag omissionNeither the start nor end tag can be omitted
Permitted parentsAny element that accepts flow content
DOM interfaceHTMLTableElement

Syntax

<table> <tr><th>Header</th></tr> <tr><td>Data</td></tr> </table>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
—Presentational attributes like border, cellpadding, and cellspacing are deprecated — style tables with CSS instead. Only the global attributes apply.

Common examples

A table with a caption and header cells

A caption names the table, and <th> cells with scope label the columns for screen readers.

<table> <caption>Opening hours</caption> <tr><th scope="col">Day</th><th scope="col">Hours</th></tr> <tr><td>Monday</td><td>9:00 – 17:00</td></tr> <tr><td>Saturday</td><td>10:00 – 14:00</td></tr> </table>

Striped rows and visible borders

Borders don’t appear by default. These rules add them and color every second row.

<style> table { border-collapse: collapse; } th, td { border: 1px solid #ccc; padding: 8px 12px; } tbody tr:nth-child(even) { background: #f5f5f8; } </style>

Make a wide table scroll on phones

Wrap the table in a div that scrolls sideways, so it doesn’t break the page layout on small screens.

<div class="table-wrap"> <table>…</table> </div> <style> .table-wrap { overflow-x: auto; } </style>

Tables vs CSS grid

An HTML <table> and CSS grid can both arrange content into rows and columns, but they mean different things. A table tells browsers, screen readers and search engines that the content is data: each cell relates to a row heading and a column heading. CSS grid is purely visual and carries no meaning at all.

Use a table for anything you would put in a spreadsheet — prices, timetables, comparisons, statistics. Use CSS grid (or flexbox) for page layout: columns of text, card galleries, headers and sidebars. Building a layout with a table makes it harder to adapt for mobile and confusing for screen reader users.

<table>CSS grid
MeaningTabular dataNone (visual only)
Screen readersAnnounce rows and columnsRead content in order
Best forData, comparisonsPage layout

Common mistakes to avoid

  • Using tables for page layout. That was common in the 1990s; today use CSS grid or flexbox. Tables are for tabular data only.
  • No header cells. Without <th> and scope, screen readers can’t tell which column or row a value belongs to.
  • Merging cells without removing others. When you add colspan or rowspan, delete the cells it now covers, or the table gets extra columns. See <tr>, <td> & <th>.
  • Skipping the caption. A <caption> tells everyone what the data is, at a glance.

Accessibility & SEO tips

  • Group rows with <thead>, <tbody> and <tfoot> so assistive technology understands the structure.
  • Keep tables simple: one header row and one header column read far better aloud than complex merged headings.
  • Search engines can lift well-structured tables straight into results, for example for comparisons and prices.
  • Avoid empty cells used only for spacing; control spacing with CSS padding so screen readers don’t announce blank cells.

Browser support

Supported in every browser, including Chrome, Edge, Firefox, Safari and their mobile versions — it has been part of HTML since the very first versions.

Related tags

Frequently asked questions

How do I make table borders show?
Use CSS: table, th, td { border: 1px solid #ccc; border-collapse: collapse; }. The border attribute alone is deprecated and produces inconsistent results.
What's the difference between <td> and <th>?
<th> is a header cell — bold and centered by default, and announced as a heading to screen readers. <td> is a regular data cell.
How do I make a table responsive on mobile?
The simplest reliable method is to wrap the table in a div with overflow-x: auto, so it scrolls sideways on small screens. For very simple tables you can also restack cells into cards with CSS.
How do I merge cells in a table?
Use colspan to stretch a cell across columns and rowspan to stretch it down rows, then remove the cells it now covers.
What does border-collapse do?
border-collapse: collapse merges the borders of neighbouring cells into a single line. Without it, each cell draws its own border, leaving double lines with gaps between them.
How do I add space between table cells?
Add padding to the cells with CSS, for example th, td { padding: 8px 12px; }. If you want gaps between cell borders, use border-spacing on the table instead, which only works when border-collapse is set to separate.