Tables
5 min read Quiz at the end
Tables organise tabular data only — never use them for page layout. Include thead, tbody, and a caption element. Always add scope to th elements. colspan spans columns and rowspan spans rows.
HTML Tables <table>
<caption>User List</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>28</td>
</tr>
</tbody>
</table>
Topic Quiz · 5 questions
Test your understanding before moving on
1. Which element wraps table header cells?
A. <thead>
B. <th>
C. <td>
D. <header>
💡 <th> marks header cells — they are bold and centred by default.
2. Which element wraps table body rows?
A. <tr>
B. <body>
C. <tbody>
D. <table>
💡 <tbody> groups the main body rows of a table.
3. The scope attribute on <th> is for:
A. Styling
B. Accessibility — tells screen readers which cells the header relates to
C. Width
D. Colour
💡 scope="col" or scope="row" helps screen readers associate headers with data cells.
4. What does <caption> do?
A. Column header
B. Table title (for accessibility)
C. Bold first row
D. Add footer
💡 <caption> provides a title for the table, displayed above it and read by screen readers.
5. Which attribute spans a cell across columns?
A. rowspan
B. colspan
C. span
D. width
💡 colspan="2" makes a cell span 2 columns.
Submit answers