HTML Tables

Beginner
14 min read
Updated: Nov 2026
6 examples
table / tr / th / td

Definition and Usage

An HTML table presents tabular data—information arranged in rows and columns so you can look up a value by matching a row with a column (price lists, schedules, scores, employee directories).

What belongs on the page?

Start with <table>, put each row in <tr>, and put each cell in <td> (data) or <th> (header). Optional caption, thead, tbody, and tfoot make larger tables clearer.

What tables are not for

Do not use tables to lay out a whole webpage (sidebars, headers, multi-column design). That belongs to CSS. Tables used only for layout are hard for assistive tech and brittle to maintain.

How do people read a table?

Sighted users connect cells visually to headers. Screen readers do the same when you mark headers with th (and scope when helpful). Good structure makes both paths work.

Data first.

Ask: “Is this a grid of related values?” If yes, a table fits. If you only need a list, use lists.

Not a layout tool.

Build page layout with CSS Flexbox or Grid. Keep <table> for real data.

Hub vs tag page.

This tutorial teaches table structure on HTML pages. Attribute-level detail for the element itself is on HTML table Tag.

HTML Syntax

Minimal table, then a structured table with headers and sections:

HTML
<table>
  <tr>
    <td>Apple</td>
    <td>Red</td>
  </tr>
  <tr>
    <td>Banana</td>
    <td>Yellow</td>
  </tr>
</table>
HTML
<table>
  <caption>Store prices</caption>
  <thead>
    <tr>
      <th scope="col">Product</th>
      <th scope="col">Price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Notebook</td>
      <td>$4.99</td>
    </tr>
  </tbody>
</table>

Core HTML Concepts

Building blocks of an HTML data table:

ElementRole
<table>Container for the whole grid
<caption>Visible title describing the table
<tr>One table row
<th>Header cell (column or row label)
<td>Data cell
<thead> / <tbody> / <tfoot>Header, body, and footer row groups
colspan / rowspanMerge a cell across columns or rows
scopeHints whether a th labels a col or row

When to use a table

ContentUse a table?
Price list, timetable, spreadsheet-like dataYes
Simple bullet featuresNo — use a list
Two-column page layoutNo — use CSS layout
Form fields in a grid of labels + inputsPrefer form layout / CSS; tables only if it is truly tabular

Spanning cells

AttributeMeaning
colspan="2"Cell covers two columns
rowspan="2"Cell covers two rows

How to Build a Table in HTML

A practical workflow:

  1. Confirm the content is tabular data (not page layout).
  2. Open <table>; add an optional <caption>.
  3. Create a header row with <th> (often inside <thead>).
  4. Add data rows with <tr> + <td> (often inside <tbody>).
  5. Use tfoot for totals; use colspan/rowspan only when needed.
  6. Style borders and spacing with CSS (border-collapse, padding)—not presentational HTML attributes from the 1990s.
GoalHTML pattern
Simple gridtable > tr > td
Labeled columnsthead > tr > th + tbody
Title above the table<caption>…</caption> first child
Merged header<th colspan="2">
Readable bordersCSS border-collapse: collapse

Live Preview

Toggle header cells and a caption on a small product table.

Headers and sections make the same data easier to read.

Preview

HTML Examples

Six patterns: basic grid, headers, sections, spanning, CSS styling, and a full employee table.

Example 1 — Basic Table

HTML
<table>
  <tr><td>Apple</td><td>Red</td></tr>
  <tr><td>Banana</td><td>Yellow</td></tr>
</table>
Try It Yourself

How It Works

  1. table wraps the grid.
  2. tr creates each row.
  3. td holds one data cell.
  4. Next step — add th headers for real datasets.

Example 2 — Header Row with th

HTML
<table>
  <thead>
    <tr><th>Product</th><th>Price</th></tr>
  </thead>
  <tbody>
    <tr><td>Notebook</td><td>$4.99</td></tr>
    <tr><td>Pen</td><td>$1.25</td></tr>
  </tbody>
</table>
Try It Yourself

How It Works

  1. th labels each column.
  2. thead groups the header row.
  3. tbody holds the data rows.
  4. Readers (and assistive tech) can connect cells to Product / Price.

Example 3 — thead, tbody, tfoot

HTML
<table>
  <thead>
    <tr><th>Item</th><th>Qty</th><th>Cost</th></tr>
  </thead>
  <tbody>
    <tr><td>Coffee</td><td>2</td><td>$6.00</td></tr>
    <tr><td>Bagel</td><td>1</td><td>$3.50</td></tr>
  </tbody>
  <tfoot>
    <tr><td colspan="2">Total</td><td>$9.50</td></tr>
  </tfoot>
</table>
Try It Yourself

How It Works

  1. tfoot holds the summary row.
  2. colspan="2" merges Item + Qty under “Total”.
  3. Sections make styling totals and headers easier.
  4. Print and long tables benefit from clear header/footer groups.

Example 4 — colspan and rowspan

HTML
<table>
  <tr><th colspan="2">Schedule</th></tr>
  <tr>
    <td rowspan="2">Mon</td>
    <td>Math</td>
  </tr>
  <tr><td>Science</td></tr>
</table>
Try It Yourself

How It Works

  1. colspan stretches “Schedule” across both columns.
  2. rowspan keeps “Mon” beside Math and Science.
  3. Do not leave empty cells that break the grid math.
  4. Use sparingly—simple grids are easier to maintain.

Example 5 — CSS Styled Table

HTML
<style>
  table { width: 100%; border-collapse: collapse; }
  th, td { border: 1px solid #ddd; padding: 8px; }
  th { background: #f4f4f4; }
  tr:nth-child(even) { background: #f9f9f9; }
</style>
<table>
  <thead><tr><th>Name</th><th>Score</th></tr></thead>
  <tbody>
    <tr><td>Alice</td><td>92</td></tr>
    <tr><td>Bob</td><td>85</td></tr>
  </tbody>
</table>
Try It Yourself

How It Works

  1. border-collapse joins adjacent borders cleanly.
  2. padding improves readability.
  3. Zebra stripes come from :nth-child, not extra HTML.
  4. Keep structure semantic; leave looks to CSS.

Example 6 — Complete Employee List

HTML
<table>
  <caption>Employee List</caption>
  <thead>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Position</th>
      <th>Department</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>John Doe</td>
      <td>Software Engineer</td>
      <td>Development</td>
    </tr>
    <tr>
      <td>2</td>
      <td>Jane Smith</td>
      <td>Project Manager</td>
      <td>Operations</td>
    </tr>
  </tbody>
</table>
Try It Yourself

How It Works

  1. caption names the dataset.
  2. thead + th define columns.
  3. tbody holds each employee row.
  4. Try It opens the full editable example.

Edge Cases & Pitfalls

Most table problems are layout misuse, missing headers, or broken spans.

layout

Using tables for page design

Use CSS for columns and sidebars. Reserve tables for data.

a11y

All cells as td with bold text

Fake headers look bold but are not announced as headers. Use th.

span

colspan/rowspan that break the grid

Count cells carefully so each row still adds up to the same column total.

mobile

Wide tables on small screens

Wrap the table in a scroll container or redesign for narrow viewports.

attr

Presentational HTML attributes

Prefer CSS over old border, bgcolor, and align attributes.

caption

Untitled complex tables

Add a caption (or nearby heading) so users know what the data describes.

Browser Support

HTML tables (table, tr, th, td, thead/tbody/tfoot, caption) are Baseline and work in every browser. Style with CSS; keep markup semantic.

✓ Baseline · Universally available

HTML data tables

Tabular markup is supported everywhere the web is rendered.

100% Table elements
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML tables Universal

Bottom line: Use tables for data with real headers—never for whole-page layout.

Key Takeaways

  • Tables are for tabular data—not page layout.
  • tr + th/td build rows; thead/tbody/tfoot organize sections.
  • caption and real th headers improve clarity and accessibility.
  • CSS handles borders and zebra stripes; tag details live on /html/tags/table.

One line: Put related values in rows and columns with table, label them with th, and leave layout to CSS.

Frequently Asked Questions

HTML tables structure tabular data—rows and columns of related values such as prices, schedules, or employee lists. Readers look up a value by matching a row with a column.
No. Tables are for data, not for arranging page regions. Use CSS (flexbox, grid) for layout. Layout tables hurt accessibility and maintenance.
This tutorial teaches how to build and use tables on an HTML page (structure, headers, sections, spanning). The /html/tags/table page is the element reference with attributes and tag-level details.
th marks a header cell (column or row label). td marks a normal data cell. Headers help browsers and screen readers associate cells with their labels.
They group header, body, and footer rows. That improves structure, styling, and printing (header/footer can repeat). Use them on real data tables.
colspan merges a cell across columns; rowspan merges across rows. Use them for titles that span the grid or labels shared by several rows—keep the grid consistent.

Practice in the editor

Open a Try It demo and build a full data table with headers and CSS.

Open Try It editor →

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.

8 people found this page helpful