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.
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 ascope. - Group rows with
<thead>,<tbody>and<tfoot>. colspanandrowspanmerge cells; use them sparingly.
Quiz: Tables