Skip to content
engineering workbench.by StudyPort Academy
Learning path
Foundations16 minLESSON 04 / 16

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.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

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.

How a data table is built
ElementWhat it marksIf you skip it
theadThe header row groupHeaders and data are one undifferentiated pile
tbodyThe data row groupThe body is harder to tell from the headers
trOne row of cellsThe cells have no row to belong to
thA header cellThe number has no label
tdOne ordinary valueThere 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.

04

Guided challenge

Tables

The scope attribute is on the th, not on a td. Read the header cell so the second log is col.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

Rain totals
col
2
table

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Which element names a column?
    02What is scope=col for?

    Ready to call this one understood?

    Mark this lesson complete to earn 100 XP. You can always revisit it.

    Sign in to save progress
    Next lesson