Build a class schedule with merged cells

Task

The starter page is a course schedule built as a flat table: double classes are written twice, the lunch break is repeated in every cell, and there are no headers or caption. Rebuild the table so repeated cells become merged cells, and headers and the note become proper table structure.

Requirements

  • The table has a <caption> with its title
  • Day names are <th scope="col"> cells inside <thead>
  • Every time slot row in <tbody> starts with a <th scope="row">
  • The double classes (HTML basics on Monday and Thursday) take two rows with rowspan="2"
  • The lunch break spans all five days (colspan="5"), and the two-day team project spans two (colspan="2")
  • The note about breaks is in <tfoot>, in one cell that spans the full width of the table
  • Once merged cells are counted, every row has the same number of columns

Starter code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Class schedule</title>
</head>
<body>
  <h1>Class schedule</h1>
  <table>
    <tr>
      <td>Time</td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td>
    </tr>
    <tr>
      <td>09:00</td><td>HTML basics</td><td>CSS</td><td>JavaScript</td><td>HTML basics</td><td>Code review</td>
    </tr>
    <tr>
      <td>10:30</td><td>HTML basics</td><td>Git</td><td>Accessibility</td><td>HTML basics</td><td>Q&amp;A</td>
    </tr>
    <tr>
      <td>12:00</td><td>Lunch break</td><td>Lunch break</td><td>Lunch break</td><td>Lunch break</td><td>Lunch break</td>
    </tr>
    <tr>
      <td>13:00</td><td>Practice</td><td>Team project</td><td>Team project</td><td>Practice</td><td>Test</td>
    </tr>
  </table>
  <p>Breaks between classes: 10 minutes.</p>
</body>
</html>
▶ Open in HTML Editor

Hints

  • A cell with rowspan="2" also takes the same column in the next row, so that row gets one <td> less for that day.
  • colspan merges cells to the right: one cell with colspan="5" replaces five separate "Lunch break" cells.
  • scope="col" marks a header for a column and scope="row" a header for a row; screen readers use it to read each cell together with its headers.
  • <caption> must be the first element inside <table>.
  • Check your table in the HTML Validator: it warns when a row ends up wider than the header row and reports an error when a merged cell stretches past the last column.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Class schedule</title>
</head>
<body>
  <h1>Class schedule</h1>
  <table>
    <caption>Web development course, week 1</caption>
    <thead>
      <tr>
        <th scope="col">Time</th>
        <th scope="col">Monday</th>
        <th scope="col">Tuesday</th>
        <th scope="col">Wednesday</th>
        <th scope="col">Thursday</th>
        <th scope="col">Friday</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">09:00</th>
        <td rowspan="2">HTML basics</td>
        <td>CSS</td>
        <td>JavaScript</td>
        <td rowspan="2">HTML basics</td>
        <td>Code review</td>
      </tr>
      <tr>
        <th scope="row">10:30</th>
        <td>Git</td>
        <td>Accessibility</td>
        <td>Q&amp;A</td>
      </tr>
      <tr>
        <th scope="row">12:00</th>
        <td colspan="5">Lunch break</td>
      </tr>
      <tr>
        <th scope="row">13:00</th>
        <td>Practice</td>
        <td colspan="2">Team project</td>
        <td>Practice</td>
        <td>Test</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="6">Breaks between classes: 10 minutes.</td>
      </tr>
    </tfoot>
  </table>
</body>
</html>

Related tools