Summary - Class schedule table
Build a weekly class schedule table using all table elements.
What we learned in this group
In this group you saw every core building block of tables:
<table>,<tr>,<td>for the table skeleton<th>andscopefor header cells<thead>,<tbody>,<tfoot>for sections<caption>for the table titlecolspanandrowspanfor cell spanning
Now we will combine all of them to build a class schedule table.
Exercise Build a class schedule table
Add a <table> to body. Right after the <table> opening, write a <caption> title (for example Weekly Class Schedule). Then add a <thead> section with <th scope="col"> headers for Day and Class. Finally add a <tbody> section with at least one <tr> row holding two <td> cells (for example Monday / Math).
Show example solution
<body>
<table>
<caption>Weekly Class Schedule</caption>
<thead>
<tr>
<th scope="col">Day</th>
<th scope="col">Class</th>
</tr>
</thead>
<tbody>
<tr>
<td>Monday</td>
<td>Math</td>
</tr>
</tbody>
</table>
</body>
Test yourself
-
Match each tag to its role
- <table>
- Table container
- <tr>
- Row
- <th>
- Header cell
- <caption>
- Title describing the table
- <thead>
- Header row section
-
Which of the following is optional in a table (not required in every table)?
- <table>
- <caption>
- <tr>
- <td>
Show answer
<caption> — Correct. <caption> is useful but not required; table, tr and td are the table's backbone.
-
Open the header section
<table> ____ <tr><th scope="col">Day</th><th scope="col">Class</th></tr> </thead> <tbody><tr><td>Monday</td><td>Math</td></tr></tbody> </table>Show answer
<table> <thead> <tr><th scope="col">Day</th><th scope="col">Class</th></tr> </thead> <tbody><tr><td>Monday</td><td>Math</td></tr></tbody> </table>