Basic Table Structure
Tables are created using the <table>
tag, with rows inside <tr>
and cells inside <td>
. Table headers use <th>
.
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Grade</th>
</tr>
<tr>
<td>Alice</td>
<td>14</td>
<td>9</td>
</tr>
</table>
Name | Age | Grade |
---|---|---|
Alice | 14 | 9 |
Bob | 15 | 10 |
Table Caption
You can add a caption above the table with <caption>
.
<table>
<caption>Class Grades</caption>
...
</table>
Merging Cells
Use colspan
to merge cells horizontally and rowspan
to merge cells vertically.
<td colspan="2">Merged Cell</td>
<td rowspan="2">Merged Cell</td>
Exercise
Create a class schedule table that includes:
- Days of the week as column headers.
- At least 3 rows for different class periods.
- A caption at the top of the table.
- One merged cell using
colspan
orrowspan
.