Tables
HTML tables exist for one specific purpose: presenting genuinely tabular data — rows and columns of related values, like a spreadsheet. They were widely misused in the early web era for general page layout; this course treats that as firmly settled history — modern layout belongs entirely to CSS, covered in the separate CSS courses, and tables here are strictly for actual tabular data.
Basic Table Structure
| Name | Role |
|---|---|
| Philip | Admin |
thead, tbody, tfoot — Grouping Rows Semantically
For anything beyond a trivial table, explicitly grouping the header row(s), body rows, and any footer row improves both semantics and styling hooks for CSS.
caption — Describing the Table's Purpose
A genuine accessibility feature, not just a visual label — screen readers announce the caption before reading the table's content, giving context about what the data actually represents before diving into individual cells.
scope — The Single Most Important Accessibility Attribute for Tables
scope="col" tells assistive technology this header applies to the entire column beneath it; scope="row" means it applies to the entire row alongside it. Without explicit scope, a screen reader has to guess at the relationship between headers and data cells — for anything beyond the simplest table, this can produce genuinely confusing or incorrect announcements.
<div>s — but doing so discards every piece of built-in table semantics covered in this chapter: row/column relationships, scope announcements, and caption support all rely on the browser recognising genuine table markup. If the data is actually tabular, use real table tags.
Spanning Cells — colspan and rowspan
colspan makes a cell span multiple columns; rowspan makes a cell span multiple rows. Genuinely useful for grouped headers, but worth using sparingly — heavily merged tables can become harder, not easier, for both sighted users and screen readers to follow correctly.
Chapter 6 Quick Reference
- table/tr/th/td — table, row, header cell, data cell — the four core building blocks
- thead/tbody/tfoot — semantic row grouping, used for anything beyond a trivial table
- caption — announced by screen readers before the table's content, real accessibility value
- scope="col" / scope="row" — the single most important table accessibility attribute, clarifies header-to-cell relationships
- colspan/rowspan — merge cells across columns/rows; use sparingly
- Tables are for tabular data only — never for general page layout, which belongs to CSS
- Next chapter: forms basics — input types, labels, and basic form structure