HTML & CSS · Beginner · 15 min
Build an accessible library hours table
Use a caption and row and column headers to make a small table easy to understand.
Name the table and group its rows
Start with <table> and put its <caption> first. Use a short caption that tells readers what the table contains. Put the header row in <thead> and the data rows in <tbody>. Each <tr> holds one row of cells. Use <th> for headers and <td> for data.
<table>
<caption>Library opening hours</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Hours</th></tr>
</thead>
<tbody>
<tr><td>Weekdays</td><td>09:00–18:00</td></tr>
</tbody>
</table>Expected appearance
Library opening hours Day | Hours Weekdays | 09:00–18:00
Connect each value to its headers
Use scope="col" on a header that labels a column. Use scope="row" on a header that labels a row. Here, a day names the row and Hours names the column. This structure helps screen readers associate an opening time with both headers.
<tbody>
<tr><th scope="row">Weekdays</th><td>09:00–18:00</td></tr>
<tr><th scope="row">Saturday</th><td>10:00–16:00</td></tr>
</tbody>Expected appearance
Weekdays | 09:00–18:00 Saturday | 10:00–16:00
Try it yourself
Code runs on this device. When you are signed in, drafts sync to your account.
Edit the page content and include CSS in a style element. The preview supports a limited set of HTML elements. Scripts, external resources, navigation to other sites, and form submission are disabled.
Build and check
Replace the list inside .hours with one <table>. Put a <caption> first. Add one row in <thead> with two <th scope="col"> cells. Add two rows in <tbody>. In each row, put the day in <th scope="row"> first, followed by one <td> for the hours. Keep the table within the narrow preview.
Put each row in a <tr>. The top row has two <th scope="col"> cells. Each data row starts with <th scope="row"> and ends with <td>.
Show worked solution
<style>
.hours { max-width: 36rem; margin: 1rem auto; font-family: sans-serif; line-height: 1.5; }
.hours table { width: 100%; border-collapse: collapse; }
.hours caption { font-weight: 700; margin-bottom: 0.5rem; }
.hours th, .hours td { padding: 0.5rem; border: 1px solid #64748b; text-align: start; }
.hours thead th { background: #eef3fa; }
</style>
<main class="hours">
<h1>Visit the library</h1>
<table>
<caption>Library opening hours</caption>
<thead>
<tr><th scope="col">Day</th><th scope="col">Hours</th></tr>
</thead>
<tbody>
<tr><th scope="row">Weekdays</th><td>09:00–18:00</td></tr>
<tr><th scope="row">Saturday</th><td>10:00–16:00</td></tr>
</tbody>
</table>
</main>The <caption> names the table. The top headers apply to columns and each day header applies to its row. A time cell can be understood in the context of both headers.
Page preview
Run to preview your page. Check tests the task requirements, including the requested screen widths. Check results do not replace keyboard and visual review.
Try it yourself
- Preview the table at a narrow width and check that the caption and both columns fit.
- Read each opening time with its day and column header. Check that both headers make sense together.