Basic

Tables that announce their structure

A table is only accessible if its structure is markup. A grid made of divs is announced as a run of unrelated text, and the listener loses which value belongs to which row. Use the table element when the data has rows and columns.

What you will see

The caption text is the conclusion a reader needs before the numbers.

About 1 min of reading

Try It

Convert a fake grid to a real table

1

Find the fake grid

grep -nE 'class="[^"]*(grid|rows?)[^"]*"' index.html | head -5

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Any div grid that holds comparable values is a candidate.
2

Write the real one

printf '
Lessons per tier
TierLessons
Basic7
' | tee -a index.html

Before you run it, say out loud what it will print. Then open the answer.

What it prints
A table with a caption and scoped column headers.
3

Style without breaking it

grep -n 'data-table' public/css/main.css

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The CSS may set borders and padding; it must not set display block on td.
4

Check the announcement

curl -s http://localhost:3000/ | grep -A2 ''

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The caption text is the conclusion a reader needs before the numbers.
Never set display:block on td or tr to make a table responsive. That destroys the announced structure for every reader.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

Data to an announced row
1 Mark the row headers with scope
↓
2 Reader enters the table and hears the caption
↓
3 Each cell is announced with its header names
↓
4 Value is understood in context
Why this works
When a table is the wrong tool

If each row is really one object with fields, a definition list or a list of small blocks is often clearer. A table is for comparing values across a shared set of columns.

Responsive tables

Reflowing a table into stacked blocks with CSS changes what the reader hears. Keep the table markup and let it scroll, or restructure the data, rather than faking a new layout.

Examples

thead and th scope

<thead> with <th scope="col"> tells the reader the header applies downward. Without scope, a complex table announces a value with no column name.

Layout is not a table

Do not use a table to position things. A table used for layout announces row and column numbers for content that has none, which is noise in the listener's ear.

Caption the table

<caption> gives the table a name so a listener can find it among several. It is the first thing announced, so put the conclusion in it.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Motion, sound, and time limits
Previous Lesson
Motion, sound, and time limits
Next Lesson
Forms that work without a mouse
Forms that work without a mouse →