A table shows data in rows and columns, like a timetable or a price list. It is built from four tags:
<table>
<tr>
<th>Day</th>
<th>Opens</th>
</tr>
<tr>
<td>Monday</td>
<td>9 am</td>
</tr>
<tr>
<td>Tuesday</td>
<td>10 am</td>
</tr>
</table>
<table>wraps the whole table.<tr>is a table row.<th>is a header cell: the label of a column. Browsers show it bold and centered.<td>is a normal data cell.
You build a table row by row. There is no tag for a column: the first cell of every row forms the first column, the second cells form the second column, and so on. That is why every row should have the same number of cells.
Use tables for data only. Years ago people used tables to arrange whole pages, which made sites hard to use on phones and with screen readers. Page layout is a job for CSS.
Tables have no lines by default. The starting code for this lesson includes one line of CSS that draws them, so you can see your cells.
Your Task
- Add a header row with two
<th>cells: Planet and Moons. - Add at least three more rows, each with a planet name and its number of moons in
<td>cells.
- The first row has two
<th>cells: Planet and Moons - There are at least three more rows
- Every other row has exactly two
<td>cells with something in them
Lesson complete!
Next Lesson: Forms