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).
Table elements
<table>contains the table;<caption>gives it a title.<tr>is a table row.<td>is a data cell;<th>is a header cell (bold and centred by default, and read by screen readers as the heading for its row or column; scope="col" or scope="row" makes the direction explicit).<thead>,<tbody>and<tfoot>group the heading rows, the body rows and the footer rows. They help screen readers, let CSS style each part and let the body scroll or print with repeated headings.- colspan makes a cell span several columns; rowspan makes it span several rows.
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?
- Each row needs 3 columns.
- The rowspan cell fills the first column of rows 2, 3 and 4.
- So rows 3 and 4 need 3 - 1 = 2 cells each.
Answer: 2 td elements each
Check yourself
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Information Technology specification (first teaching 2018), Unit 2 Topics 7 to 11
- Pearson qualifications: Edexcel International Advanced Level Information Technology (2018)
Last updated 8 November 2026. Spotted a mistake? Tell us.