edubun
English
1 / 15

7 / 10 · Intro

Tables

A bus timetable is a table: every cell only makes sense together with its row heading and its column heading.

Jump to the 10 practice questions

You will learn

  • Add caption, thead, tbody and scope so the table explains itself

Before this: Lists

1Explain

Rows, cells and headers

A table is built row by row. <table> wraps everything, each <tr> (table row) is one row, and inside a row each <td> (table data) is one cell. Cells that label a row or a column use <th> (table header) instead, which browsers show in bold and centre by default. The number of cells in each row should match, so the columns line up.

Your code
<table>
  <caption>Bread prices, October 2026</caption>
  <thead>
    <tr><th scope="col">Loaf</th><th scope="col">Weight</th><th scope="col">Price</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Sourdough</th><td>800 g</td><td>6.50</td></tr>
    <tr><th scope="row">Rye</th><td>600 g</td><td>5.00</td></tr>
  </tbody>
</table>
Preview

2Problem

One row

Which element is one row?

Hint

Short for table row.

Solution

Answer: tr

tr, table row.

3Problem

A column label

Which element labels a column?

Hint

Header cells use a different element from data cells.

Solution

Answer: th

th is a header cell; td holds data.

4Explain

Make the table explain itself

Three additions turn a grid of cells into a table that everyone can read. First, <caption>, placed right after the opening <table> tag, gives the table a title; screen readers announce it before the contents, so the listener knows what the table is about. Second, the scope attribute on each <th> says whether it labels a column (scope="col") or a row (scope="row").

Your code
<table border="1">
  <caption>Opening hours</caption>
  <thead>
    <tr><th scope="col">Day</th><th scope="col">Open</th><th scope="col">Close</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Monday</th><td>7:00</td><td>18:00</td></tr>
    <tr><th scope="row">Sunday</th><td>Closed</td><td>Closed</td></tr>
  </tbody>
</table>
Preview

5Problem

scope="row"

What does scope="row" on a th mean?

Hint

The header labels the cells beside it in the same row.

Solution

Answer: It labels the cells in its row

scope tells assistive technology which cells a header describes.

6Explain

Example: from a list of facts to a table

The bakery delivers to the north of town on Tuesdays and to the south on Thursdays. Turn these two facts into a table.

  1. Decide what one row is: one area. Two areas give two body rows.
  2. Decide what the columns are: the area and the delivery day. Their names go in a header row of th cells with scope="col".
  3. The area names label their rows, so they are th with scope="row"; the days are data, so they are td.
  4. Every row has 2 cells, so the columns line up. caption, right after the opening table tag, names the table.
Your code
<table border="1">
  <caption>Delivery days</caption>
  <thead>
    <tr><th scope="col">Area</th><th scope="col">Day</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">North</th><td>Tuesday</td></tr>
    <tr><th scope="row">South</th><td>Thursday</td></tr>
  </tbody>
</table>
Preview

7Problem

Where the caption goes

Where is caption written?

Hint

Screen readers announce it before the contents.

Solution

Answer: Right after the opening table tag

caption is the first child of table, so the title comes before the rows.

8Explore

Cells that span

A cell can stretch across several columns with colspan or several rows with rowspan. In a weekly timetable, a lunch break that covers all five weekdays can be one cell with colspan="5". When a cell spans, the row it sits in needs fewer cells: if a row normally has 6 cells and one of them has colspan="5", that row contains only 2 cells in the HTML.

A cell with colspan="3" takes the room of three cells, so that row needs fewer td elements.

Tap a choice: the code and the preview change together.

Second row
<table border="1">
  <tr><th>Mon</th><th>Tue</th><th>Wed</th></tr>
  <tr><td>Lunch</td><td>Lunch</td><td>Lunch</td></tr>
</table>
Preview

9Problem

How many cells are written?

A row normally has 6 cells. One cell has colspan="4". How many cells are written in that row?

Hint

One cell covers 4 of the 6 places.

Solution

Answer: 3

The spanning cell takes the place of 4, so 6 minus 4 plus 1 is 3 cells.

10Problem

After a rowspan

A table has 3 columns. In row 2, the first cell has rowspan="2". How many cells are written in row 3?

Hint

The cell from row 2 also fills one place in row 3.

Solution

Answer: 2

rowspan="2" stretches the cell down into row 3, so row 3 has only 3 − 1 = 2 places left to write.

11Problem

A table for layout?

Someone uses a table only to place a photo to the left of some text. Is that a good use?

Hint

Think of a screen reader announcing rows and columns.

Solution

Answer: No: tables are for data; use CSS for layout

A table tells assistive technology that the content is data in rows and columns. For placing things side by side, CSS is the tool.

12Practice

Caption, thead and tbody

Add a <caption> that says Opening hours. Move the first row into a <thead>, make its cells <th scope="col">, and put the other rows in a <tbody>.

Checks
  • caption
  • 3 column headers in thead
  • 3 rows in tbody
Your code
<table>
  <tr><td>Day</td><td>Open</td><td>Close</td></tr>
  <tr><td>Monday</td><td>7:00</td><td>18:00</td></tr>
  <tr><td>Saturday</td><td>8:00</td><td>14:00</td></tr>
  <tr><td>Sunday</td><td>Closed</td><td>Closed</td></tr>
</table>
Preview
Hint

caption comes right after <table>. The first row moves into thead, the others into tbody.

A solution
<table>
  <caption>Opening hours</caption>
  <thead>
    <tr><th scope="col">Day</th><th scope="col">Open</th><th scope="col">Close</th></tr>
  </thead>
  <tbody>
    <tr><td>Monday</td><td>7:00</td><td>18:00</td></tr>
    <tr><td>Saturday</td><td>8:00</td><td>14:00</td></tr>
    <tr><td>Sunday</td><td>Closed</td><td>Closed</td></tr>
  </tbody>
</table>

13Practice

One lunch cell

The lunch break is the same on every day. Replace the three Lunch cells with one cell that spans 3 columns.

Checks
  • colspan="3" cell
  • only one Lunch cell
Your code
<table>
  <tr><th scope="col">Time</th><th scope="col">Mon</th><th scope="col">Tue</th><th scope="col">Wed</th></tr>
  <tr><th scope="row">9:00</th><td>Maths</td><td>Art</td><td>Music</td></tr>
  <tr><th scope="row">12:00</th><td>Lunch</td><td>Lunch</td><td>Lunch</td></tr>
</table>
Preview
Hint

Keep the 12:00 header and write a single td with colspan="3".

A solution
<table>
  <tr><th scope="col">Time</th><th scope="col">Mon</th><th scope="col">Tue</th><th scope="col">Wed</th></tr>
  <tr><th scope="row">9:00</th><td>Maths</td><td>Art</td><td>Music</td></tr>
  <tr><th scope="row">12:00</th><td colspan="3">Lunch</td></tr>
</table>

14Explain

Common mistakes

Mistake
<table border="1">
  <tr><td><b>Day</b></td><td><b>Open</b></td></tr>
  <tr><td>Monday</td><td>7:00</td></tr>
</table>
Fixed
<table border="1">
  <tr><th scope="col">Day</th><th scope="col">Open</th></tr>
  <tr><td>Monday</td><td>7:00</td></tr>
</table>

Bold cells only look like headers. A screen reader cannot tell which cell labels which; th with scope says it.

15

Summary

  • Tables are for data: table, tr, th, td.
  • caption names the table; scope ties headers to cells; thead, tbody, tfoot group rows.
  • colspan and rowspan merge cells; keep tables simple.

Next unitForms basics
Full text · The whole lesson as one text

Tables are for data

Use a table when information has rows and columns: a timetable, a price list, the results of a survey. In the late 1990s many sites used tables to build whole page layouts, with menus in one cell and content in another. That causes real problems. Screen readers announce every cell with its row and column, so a layout table sounds like a confusing spreadsheet, and table layouts do not adapt well to small screens. Today layout is done with CSS, and tables are kept for data.

Rows, cells and headers

A table is built row by row. <table> wraps everything, each <tr> (table row) is one row, and inside a row each <td> (table data) is one cell. Cells that label a row or a column use <th> (table header) instead, which browsers show in bold and centre by default. The number of cells in each row should match, so the columns line up.

<table>
  <caption>Bread prices, October 2026</caption>
  <thead>
    <tr><th scope="col">Loaf</th><th scope="col">Weight</th><th scope="col">Price</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Sourdough</th><td>800 g</td><td>6.50</td></tr>
    <tr><th scope="row">Rye</th><td>600 g</td><td>5.00</td></tr>
  </tbody>
</table>
A caption, a header row in thead, and row headers in the first column.

Make the table explain itself

Three additions turn a grid of cells into a table that everyone can read. First, <caption>, placed right after the opening <table> tag, gives the table a title; screen readers announce it before the contents, so the listener knows what the table is about. Second, the scope attribute on each <th> says whether it labels a column (scope="col") or a row (scope="row"). With it, a screen reader can read Rye, Price, 5.00 instead of a bare 5.00. Third, <thead>, <tbody> and <tfoot> group the header rows, the body rows and any total rows. They make the structure clear, help CSS style each part, and let browsers repeat the header on every printed page of a long table.

Cells that span

A cell can stretch across several columns with colspan or several rows with rowspan. In a weekly timetable, a lunch break that covers all five weekdays can be one cell with colspan="5". When a cell spans, the row it sits in needs fewer cells: if a row normally has 6 cells and one of them has colspan="5", that row contains only 2 cells in the HTML. Use spanning when it reflects the data; very complex tables are hard for everyone to read, so splitting one big table into two simpler ones is often better.

Wide tables can be a problem on phones. A table cannot wrap the way text does, so a table with many columns may be wider than the screen. A common fix is to wrap the table in an element that scrolls sideways on its own, using CSS, so the rest of the page does not get wider too.

Keep the data in each cell as plain as you can: one value per cell, units in the header (Price in euros) rather than repeated in every cell, and no empty cells used as spacers. A table built this way is easier to read aloud, easier to sort, and pastes cleanly into a spreadsheet.

Key points
  • Tables are for data: table, tr, th, td.
  • caption names the table; scope ties headers to cells; thead, tbody, tfoot group rows.
  • colspan and rowspan merge cells; keep tables simple.

Practice questions from Tables on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (9)
  • WHATWG, HTML Living Standard (html.spec.whatwg.org, checked 2026-10-17)
  • MDN Web Docs, Learn web development: Structuring content with HTML, and the HTML element reference (developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content and developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements, checked 2026-10-17)
  • MDN, HTML images (alt text guidance, checked 2026-10-17)
  • W3C WAI, Images tutorial and alt decision tree (w3.org/WAI/tutorials/images/decision-tree, checked 2026-10-17)
  • CERN, A short history of the Web (home.cern/science/computing/the-birth-of-the-web/short-history-web/, checked 2026-10-17)
  • W3C and WHATWG memorandum of understanding, 28 May 2019 (w3.org/2019/04/WHATWG-W3C-MOU.html, checked 2026-10-17)
  • W3C, Using ARIA, first rule of ARIA use (w3.org/TR/using-aria/, checked 2026-10-17)
  • W3C Markup Validation Service (validator.w3.org, checked 2026-10-17)
  • MDN, Viewport meta element (checked 2026-10-17).

Checked: 2026-10-17