Learn how to structure data into rows and columns and present it as a table.
1. What Is a Table?
An HTML table arranges data in a grid made of rows and columns.
Think of it as expressing an Excel spreadsheet in HTML.
Note: Tables are used to present data.
In the past, tables were also used to lay out web pages,
but today the correct approach is to use CSS Flexbox/Grid.
2. Basic Table Structure
<table>
<thead> <!-- table header section -->
<tr> <!-- row (table row) -->
<th>Name</th> <!-- header cell (table header) -->
<th>Age</th>
<th>Occupation</th>
</tr>
</thead>
<tbody> <!-- table body section -->
<tr>
<td>John Doe</td> <!-- data cell (table data) -->
<td>25</td>
<td>Student</td>
</tr>
<tr>
<td>Chris Kim</td>
<td>30</td>
<td>Developer</td>
</tr>
</tbody>
<tfoot> <!-- table footer section -->
<tr>
<td colspan="3">2 people in total</td> <!-- colspan: merge multiple columns -->
</tr>
</tfoot>
</table>
3. Table Tags in Detail
table
The top-level tag that wraps the entire table.
<table border="1"> <!-- the border attribute is not recommended in HTML5. Use CSS instead -->
thead, tbody, tfoot
These split a table into three sections:
| Tag | Role | Characteristics |
|---|---|---|
<thead> |
Header rows | Usually holds the column titles |
<tbody> |
Body data rows | Holds the actual data; optional, but recommended |
<tfoot> |
Footer rows | Holds totals, summaries, and so on |
<table>
<thead>
<tr>
<th>Item</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>Food</td>
<td>₩300,000</td>
</tr>
<tr>
<td>Transportation</td>
<td>₩50,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>₩350,000</td>
</tr>
</tfoot>
</table>
tr - Row (Table Row)
Represents one row of a table. Used inside <thead>, <tbody>, and <tfoot>.
th - Header Cell (Table Header)
<th scope="col">Name</th> <!-- column heading -->
<th scope="row">Row 1</th> <!-- row heading -->
- By default they are displayed in bold and centered.
- The
scopeattribute states which direction the heading applies to (important for accessibility)
td - Data Cell (Table Data)
<td>John Doe</td>
<td>25</td>
<td>Seoul</td>
4. Merging Cells
colspan - Column Merge
Merges several cells horizontally.
<table border="1">
<tr>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
</tr>
<tr>
<td>Math</td>
<td colspan="2">English (2 hours)</td> <!-- merge 2 columns -->
</tr>
</table>
Result:
┌─────┬─────┬─────┐
│ Mon │ Tue │ Wed │
├─────┼───────────┤
│Math │ English(2)│
└─────┴───────────┘
rowspan - Row Merge
Merges several cells vertically.
<table border="1">
<tr>
<th>Name</th>
<th>Subject</th>
<th>Score</th>
</tr>
<tr>
<td rowspan="2">John Doe</td> <!-- merge 2 rows -->
<td>Math</td>
<td>90</td>
</tr>
<tr>
<!-- the cell merged by rowspan occupies this position, so td is omitted -->
<td>English</td>
<td>85</td>
</tr>
</table>
Result:
┌──────────┬─────────┬──────┐
│ Name │ Subject │Score │
├──────────┼─────────┼──────┤
│ │ Math │ 90 │
│ John Doe ├─────────┼──────┤
│ │ English │ 85 │
└──────────┴─────────┴──────┘
Using colspan and rowspan Together
<table border="1">
<tr>
<th>Category</th>
<th colspan="2">Semester 1</th> <!-- merge 2 columns -->
<th colspan="2">Semester 2</th> <!-- merge 2 columns -->
</tr>
<tr>
<th>Name</th>
<th>Midterm</th>
<th>Final</th>
<th>Midterm</th>
<th>Final</th>
</tr>
<tr>
<td rowspan="2">Seoul Class</td> <!-- merge 2 rows -->
<td>John Doe 90</td>
<td>John Doe 85</td>
<td>John Doe 88</td>
<td>John Doe 92</td>
</tr>
<tr>
<!-- the space taken by the cell merged with rowspan -->
<td>Emma Kim 95</td>
<td>Emma Kim 91</td>
<td>Emma Kim 93</td>
<td>Emma Kim 97</td>
</tr>
</table>
5. The scope Attribute (Accessibility)
Set scope on <th> tags so that screen readers read the table correctly.
<table>
<thead>
<tr>
<th scope="col">Name</th> <!-- this th is the heading for a column -->
<th scope="col">Math</th>
<th scope="col">English</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Class 1</th> <!-- this th is the heading for a row -->
<td>90</td>
<td>85</td>
</tr>
<tr>
<th scope="row">Class 2</th>
<td>88</td>
<td>92</td>
</tr>
</tbody>
</table>
6. caption - Table Title
<table>
<caption>Q1 2026 Sales Results</caption>
<!-- caption: the table's title. Write it first, directly inside the table -->
<thead>
...
</thead>
</table>
Summary
| Tag/Attribute | Description |
|---|---|
<table> |
Container for the whole table |
<caption> |
Table title |
<thead> |
Table header section |
<tbody> |
Table body section |
<tfoot> |
Table footer section |
<tr> |
Row (Table Row) |
<th> |
Header cell (bold, centered) |
<td> |
Data cell |
colspan="n" |
Merge n columns (horizontal) |
rowspan="n" |
Merge n rows (vertical) |
scope="col" |
Declares that this th is a column heading |
scope="row" |
Declares that this th is a row heading |
Next Steps
- View the example file - a weekly class timetable example
- Check the assignment - build a monthly expense report
- Next lesson: Forms