Tables
Some information really is rows and columns. A table is the element for that relationship. A caption and header cells keep the meaning attached to the numbers.
Your console output appears here.
The console read the caption, the header scope, the number of data cells, and the table tag. The rows were already in the HTML.
+Go deeper
When a table is the right tool
Use a table when the meaning is a relationship: this rain total belongs under this month. A list of articles is not that relationship. A for a data relationship is table, not a pile of divs aligned with spacing.
The caption is the title
caption is the name of the table, tied to it. A paragraph above the table can look like a title and still be a separate paragraph. Put the name in caption.
Header cells name columns
th is a header cell. td is an ordinary value. thead groups the header row, tbody groups the data rows, and tr groups the cells of one row. The first row of month names should be th, not bold td. The header is how a reader knows what 12 measures.
| Element | What it marks | If you skip it |
|---|---|---|
| thead | The header row group | Headers and data are one undifferentiated pile |
| tbody | The data row group | The body is harder to tell from the headers |
| tr | One row of cells | The cells have no row to belong to |
| th | A header cell | The number has no label |
| td | One ordinary value | There is nothing to measure |
Scope points at the cells
scope=col means the header names the column beneath it. scope=row names the row beside it. Use scope when a table has both kinds of headers so each value can find its labels.
Layout is not a table
Later lessons place regions with CSS. This lesson is only the data table. If you removed the borders, the caption and headers should still explain every number.
Guided challenge
Tables
The scope attribute is on the th, not on a td. Read the header cell so the second log is col.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
Rain totals col 2 table
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.