TetSharing
HTML tutorial · 12 chapters
  1. Get started
  2. Elements and attributes
  3. Headings and paragraphs
  4. Text formatting
  5. Links
  6. Images
  7. Lists
  8. Tables
  9. Forms
  10. Input types and controls
  11. Semantic layout
  12. Head and metadata

Final HTML quiz

Chapter 8 of 12 · By Ethan Cole · Updated November 21, 2026

HTML Tables: table, tr, th, td, caption and scope

Tables present tabular data: information that makes sense in rows and columns, like prices, schedules or comparison charts. They are not a layout tool. Page layout belongs to CSS (flexbox and grid), and using tables for it confuses screen readers and breaks on small screens.

The building blocks

  • <table> wraps everything.
  • <tr> is a table row.
  • <td> is a data cell and <th> is a header cell.
  • <caption>, placed right after the opening <table> tag, gives the table a visible title. It is the table's accessible name, so screen-reader users hear it before the data.

Header cells and scope

Header cells label the data. scope="col" says a header applies to the cells below it, and scope="row" says it applies to the cells to its right. With scopes in place, a screen reader can announce "Price, $12.50" as the user moves between cells, instead of a bare number.

Row groups

<thead>, <tbody> and <tfoot> group rows into a header, a body and a footer, such as a totals row. They make the structure explicit, let CSS style each group, and when a long table is printed, browsers can repeat the header on every page. If you leave out <tbody>, the browser adds one for you.

HTML · editable

Expected page text

Bestsellers, October 2026
Title | Author | Price
Paper Cranes | Aiko Tanaka | $11.00
The Last Lantern | Daniel Okafor | $12.50
Total | $23.50

Merging cells

colspan="2" makes a cell span two columns, as the "Total" header does in the footer, and rowspan="2" makes it span two rows. Use merging sparingly. Every merged cell makes the grid harder to follow, both visually and for assistive technology, and a simpler table, or two tables, is often clearer.

Making tables readable

Tables have no borders by default; the example's <style> block adds them. Right-align numeric columns so digits line up, and keep units in the header ("Price, USD") rather than repeating them in every cell when you can. On narrow screens, wrap a wide table in a container with overflow-x: auto so it can scroll sideways without breaking the page layout.

Common mistakes

  • Using tables for page layout.
  • Using <td> with bold text instead of <th> for headers.
  • Forgetting the caption, so the table has no name.
  • Putting text directly inside <tr> or <table> outside any cell; browsers move it out of the table.

Summary

  • Tables are for data: <table>, <tr>, <th>, <td>.
  • Give each table a <caption> and each header a scope.
  • Group rows with <thead>, <tbody> and <tfoot>.
  • colspan and rowspan merge cells; use them sparingly.

Quiz: Tables

1. Which element should label a column of data?

Header cells with a scope tell assistive technology what each column means.

2. Where does <caption> go?

The caption must be the first child of the table.

3. What does colspan="3" do?

colspan merges a cell horizontally across columns.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.