Table
A table is a pattern for organizing and listing data in rows and columns. When heading cells, scope, and captions are set correctly, assistive technology can understand the structure as intended.
When to use / not use
Use it when
- When users need to compare multiple items
- When meaning emerges from the intersection of rows and columns
- When you want to present spreadsheet-like data in a structured list
Don't use it when
- For layout purposes → use CSS Grid or Flexbox
- For simple lists → use
ulorol - When there are too many columns for a responsive table → consider a card layout
Anatomy
- Caption — Briefly explains the purpose or content of the table
- Heading cells — Use
thfor row or column headings and declare direction withscope - Data cells — Use
tdfor the actual data content - Scope — Use
scope="col"orscope="row"to express the relationship between headers and data
HTML Structure
Key points
- Use a
captionelement to state the purpose of the table - Separate heading rows and data rows structurally with
theadandtbody - Use
th scope="col"for column headings andth scope="row"for row headings - For complex tables, use the
headersattribute to associate cells with headings explicitly
CSS Implementation
Styling points
- Borders — Use
border-collapse: collapseto avoid double borders between cells - Striping — Use
nth-childto alternate row backgrounds and improve scanability - Responsive handling — Wrap the table in an
overflow-x: autocontainer for horizontal scrolling - Sticky header — Use
position: stickywhen the header row should stay visible during vertical scrolling
Accessibility
WCAG 1.3.1 Info and Relationships
Heading cells and scope need to communicate the relationship between headers and data programmatically.
WCAG 1.3.2 Meaningful Sequence
The table data needs to be announced in a logical order.
WCAG 2.1.1 Keyboard
Any links or buttons inside the table need to be operable with the keyboard.
Keyboard operation
- Use Tab to move to interactive elements inside the table
- In screen readers, users can move between cells with table navigation commands
- A caption helps users understand the table purpose before entering it
Live Demo
Striped table
A variation that improves scannability with alternating row backgrounds.
Responsive table
A pattern that preserves the table layout on mobile through horizontal scrolling.
Common mistakes
Using tables for layout
If you use a table for anything other than tabular data, assistive technology conveys the wrong structure.
Using only td and no th
Without heading cells, screen reader users cannot understand what each cell means.
No caption, so the purpose is unclear
Without a caption or equivalent explanation, users have a harder time understanding what the table represents.