All subjects · Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript

HTML tables: rows, cells, headings and merged cells

Edexcel IAL Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript

Tables show data in rows and columns. You need rows, data cells, header cells, the head, body and foot sections, and merged cells (spec 7.3.2).

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

Table elements

A worked table

<table>
  <caption>Pool timetable</caption>
  <thead>
    <tr>
      <th>Time</th>
      <th>Monday</th>
      <th>Tuesday</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>9am</td>
      <td colspan="2">Lane swimming</td>
    </tr>
    <tr>
      <td>10am</td>
      <td rowspan="2">Aqua fit</td>
      <td>Lessons</td>
    </tr>
    <tr>
      <td>11am</td>
      <td>Family swim</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="3">Times may change in school holidays.</td>
    </tr>
  </tfoot>
</table>

This table has 5 rows, 3 header cells and 8 data cells. 'Lane swimming' covers two columns (colspan="2"). 'Aqua fit' covers two rows (rowspan="2"), so the 11am row has only two td elements: the Monday cell is already filled from the row above.

Counting cells

Every row must add up to the same number of columns. A cell with colspan="n" counts as n columns. A cell with rowspan="n" takes one column in each of the next n - 1 rows too, so those rows need one fewer td. Tables are for tabular data only, not for page layout: use CSS for layout.

Worked example

A table has three columns. The second row's first cell has rowspan="3". How many td elements do the third and fourth rows each need?

  1. Each row needs 3 columns.
  2. The rowspan cell fills the first column of rows 2, 3 and 4.
  3. So rows 3 and 4 need 3 - 1 = 2 cells each.

Answer: 2 td elements each

Key idea: table, caption, tr (row), td (data cell), th (header cell), thead, tbody, tfoot; colspan merges across columns, rowspan merges down rows. Use tables for data, never for layout.

Check yourself

  1. How many td (data cell) elements does this table contain in total? ```html <table> <caption>Pool timetable</caption> <thead> <tr> <th>Time</th> <th>Monday</th> <th>Tuesday</th> </tr> </thead> <tbody> <tr> <td>9am</td> <td colspan="2">Lane swimming</td> </tr> <tr> <td>10am</td> <td rowspan="2">Aqua fit</td> <td>Lessons</td> </tr> <tr> <td>11am</td> <td>Family swim</td> </tr> </tbody> <tfoot> <tr> <td colspan="3">Times may change in school holidays.</td> </tr> </tfoot> </table> ```
    Show answer

    8. Counting the td tags: 8.

  2. Which attribute makes one cell stretch across three columns?
    • rowspan="3"
    • span="3"
    • cols="3"
    • colspan="3"
    Show answer

    colspan="3". colspan merges cells across columns; rowspan merges down rows.

  3. Which element creates a header cell in a table? Type the element name.
    Show answer

    th. th is a table header cell; td is a data cell.

  4. A 4-column table has a cell with rowspan="2" in its first row. How many td elements does the second row need?
    • 4
    • 2
    • 3
    • 5
    Show answer

    3. The rowspan cell also fills one column of row 2, so row 2 needs 4 - 1 = 3 cells.

  5. Which element groups the summary or footnote rows at the bottom of a table?
    • `<tfoot>`
    • `<thead>`
    • `<caption>`
    • `<footer>`
    Show answer

    `<tfoot>`. tfoot groups footer rows. footer is a page section element, not part of a table.

  6. Why should tables not be used to lay out a whole web page?
    Show answer

    Tables are for tabular data; using them for layout confuses screen readers and makes the page hard to make responsive, so CSS should be used for layout instead.. Layout tables give the wrong meaning to assistive technology, are hard to adapt to different screen sizes and mix content with presentation. CSS does layout.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.