A schedule is easier to read when each start time stays paired with its session. An HTML table keeps those pairs in rows under shared column headings.

A caption gives the table a name. Column header cells identify what each column contains so assistive technology can give a value the context of its heading.

A single header row works when every row has the same fields in the same order. An empty data cell holds a missing value's place so the cells that follow stay under their own headings.

Steps to create an HTML table:

  1. Create schedule.html in a new test folder using your text editor.
  2. Enter the HTML document structure in schedule.html.
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Workshop schedule</title>
      <style>
        body {
          font: 24px system-ui, sans-serif;
          margin: 2rem;
        }
        table {
          border-collapse: collapse;
        }
        th, td {
          border: 1px solid;
          padding: 0.4rem 0.75rem;
        }
      </style>
    </head>
    <body>
    </body>
    </html>

    The styles make the cell boundaries visible. The table markup belongs inside <body>, including when a template generates the page.

  3. Add the table and its heading row inside <body>.
      <table>
        <caption>Workshop schedule</caption>
        <thead>
          <tr>
            <th scope="col">Session</th>
            <th scope="col">Start time</th>
          </tr>
        </thead>
      </table>

    A <tr> holds the cells for one row. Each <th scope="col"> identifies a heading for the data cells below it in that column. The W3C tutorial Tables with row and column headers shows how to add a heading for each row as well.

  4. Insert the data rows immediately before </table>.
        <tbody>
          <tr>
            <td>Woodworking</td>
            <td>10:00</td>
          </tr>
          <tr>
            <td>Printmaking</td>
            <td>11:30</td>
          </tr>
        </tbody>

    Each <td> is a data cell. The session goes first and its start time goes second, in the order set by the headings.

  5. Save schedule.html.
  6. Open the saved schedule.html in desktop Chrome using its file URL.

    The address uses the full path to your file, such as file:///home/user/site/schedule.html or file:///C:/site/schedule.html on Windows.

  7. Right-click the Session heading in the rendered table.
  8. Select Inspect in the context menu.
  9. Verify that Session and Start time appear as <th scope="col"> elements in Elements.

    The rendered Workshop schedule beside DevTools shows Woodworking at 10:00 and Printmaking at 11:30 under the two headings. A <td> in the heading row still has the semantics of a data cell even when it looks like a heading.

Share this guide