Tables (table, tr, td, th)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This Tables (table, tr, td, th) worksheet is part of the HTML and CSS Journey journey. Print it as a booklet?

Tables (table, tr, td, th)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which element wraps the entire table?
A <tr>
B <table>
2. Which element creates a single row inside a table?
A <tr>
B <td>
3. What is the difference between <td> and <th>?
A <th> is a header cell, bold by default; <td> is a data cell
B <th> is for tables; <td> is for div containers
4. True or false: <td> cells can be placed directly inside <table> without a <tr>.
A True
B False
5. True or false: <TABLE> with capital letters is valid HTML.
A False
B True

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1<table> <tr><th>Name</th><th>Age</th></tr> <tr><td>Alice</td><td>25</td></tr> </table> A<table> <tr><th>Product</th><th>Price</th></tr> </table>
2<tr><td>Sydney</td><td>5m</td></tr> B<table> <tr> <td>Alice</td> <td>95</td> </tr> </table>
3<th> creates a header cell - bold and centred by default, used for column or row labels CA complete table - <table> wraps everything, <tr> defines rows, <th> labels columns, <td> holds data
4Every <td> and <th> must be inside a <tr>, and every <tr> must be inside <table> DAll table tag names must be lowercase - <TABLE>, <TR>, <TH> should be <table>, <tr>, <th>
5<table> <td>Name</td> <td>Score</td> </table> E<td> cells must be inside a <tr> row - add <tr></tr> wrappers around the cells
6<TABLE> <TR><TH>Name</TH></TR> </TABLE> FOne table row with two data cells - the row wraps two <td> elements containing city name and population

Definitions

<tr>

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
<___> <tr><td>Data</td></tr> </table>
2.
<table> <___><th>Name</th></tr> </table>
3.
<table> <tr><___>Score</th></tr> </table>
4.
<table> <tr><___>Alice</td></tr> </table>
5.
<table> <tr><th>City</th></tr> <tr><td>Sydney</td></tr> </___>

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A <TABLE>
B <tr><th>Name</th><th>Age</th></tr>
C <tr><td>Alice</td><td>25</td></tr>
D </table>
Question 2
A <table>
B <tr><TD>Name</TD><TD>Score</TD></tr>
C <tr><td>Alice</td><td>95</td></tr>
D </table>
Question 3
A <table>
B <tr><th>Item</th><th>Price</th></tr>
C <TR><td>Apple</td><td>$1</td></TR>
D </table>
Question 4
A <table>
B <tr><th>Name</th><th>Age</th></tr>
C <tr><td>Alice</td><td>25</td></tr>
D <td>Bob</td><td>30</td>
E </table>
Question 5
A <table>
B <tr>
C <th>Product</th>
D <th>Price</th>
E <tr>
F </table>

Answer Key

Tables (table, tr, td, th)
Section A: Quick Questions
Q1
B — <table>
Q2
A — <tr>
Q3
A — <th> is a header cell, bold by default; <td> is a data cell
Q4
B — False
Q5
A — False
Section B: Match the Pairs
Q1
<table> <tr><th>Name</th><th>Age</th></tr> <tr><td>Alice</td><td>25</td></tr> </table> → A complete table - <table> wraps everything, <tr> defines rows, <th> labels columns, <td> holds data
Q2
<tr><td>Sydney</td><td>5m</td></tr> → One table row with two data cells - the row wraps two <td> elements containing city name and population
Q3
<th> creates a header cell - bold and centred by default, used for column or row labels → <table> <tr><th>Product</th><th>Price</th></tr> </table>
Q4
Every <td> and <th> must be inside a <tr>, and every <tr> must be inside <table> → <table> <tr> <td>Alice</td> <td>95</td> </tr> </table>
Q5
<table> <td>Name</td> <td>Score</td> </table> → <td> cells must be inside a <tr> row - add <tr></tr> wrappers around the cells
Q6
<TABLE> <TR><TH>Name</TH></TR> </TABLE> → All table tag names must be lowercase - <TABLE>, <TR>, <TH> should be <table>, <tr>, <th>
Section C: Definitions
Q1
<tr> — An HTML element that creates one horizontal row inside a table. Every <td> and <th> cell must sit inside a <tr>.
Section D: Fill in the Blanks
Q1
<table> <tr><td>Data</td></tr> </table>
Q2
<table> <tr><th>Name</th></tr> </table>
Q3
<table> <tr><th>Score</th></tr> </table>
Q4
<table> <tr><td>Alice</td></tr> </table>
Q5
<table> <tr><th>City</th></tr> <tr><td>Sydney</td></tr> </table>
Section E: Spot the Error
Q1
A — HTML tag names must be lowercase. <TABLE> should be written as <table>.
Q2
B — HTML tag names must be lowercase. <TD> and </TD> should be written as <td> and </td>.
Q3
C — HTML tag names must be lowercase. <TR> and </TR> should be written as <tr> and </tr>.
Q4
D — Each row's cells must be wrapped inside a <tr> element. The cells for Bob are missing their enclosing <tr></tr> tags.
Q5
E — The second <tr> is an opening tag - it should be the closing tag </tr> to end the header row.