MaraHTML
Coding resources, tutorials and more.
HTML Tables
Share this page:
A table represents information in a grid format.
Note: The tables used in the example have some basic CSS formatting just to make them easier to follow.
Basic table structure
- The <table> tag is used to create a table.
- The <tr> tag indicates the start of a new table.
- The <td> tag represents an individual cell of a table.
- The <th> tag is used like the <td> tag but it represents the heading of either a row or column. Even if a cell has no content use the <td> or <th> elements to represent an empty cell.
Now to watch the code in action.
<table>
<tr>
<tr>
<tr>
</table>
<th></th>
<th>Addow</th>
<th>Arinya</th>
<th>Azul</th>
</tr><th>Addow</th>
<th>Arinya</th>
<th>Azul</th>
<tr>
<th>Alien</th>
<td></td>
<td><img src="http://images.marapets.com/pets/Arinya_alien.gif"></td>
<td><img src="http://images.marapets.com/pets/Azul_alien.gif"></td>
</tr><td></td>
<td><img src="http://images.marapets.com/pets/Arinya_alien.gif"></td>
<td><img src="http://images.marapets.com/pets/Azul_alien.gif"></td>
<tr>
<th>American</th>
<td><img src="http://images.marapets.com/pets/Addow_american.gif"></td>
<td><img src="http://images.marapets.com/pets/Arinya_american.gif"></td>
<td></td>
</tr>
<td><img src="http://images.marapets.com/pets/Addow_american.gif"></td>
<td><img src="http://images.marapets.com/pets/Arinya_american.gif"></td>
<td></td>
Addow | Arinya | Azul | |
---|---|---|---|
Alien | |||
American |
Spanning columns and rows
For some tables you need some cells merged together. This is done using the colspan and rowspan attributes.
<table>
<tr>
<tr>
</table>
<th></th>
<th>09:00</th>
<th>10:00</th>
<th>11:00</th>
</tr><th>09:00</th>
<th>10:00</th>
<th>11:00</th>
<tr>
<th>Monday</th>
<th rowspan="2">Art</th>
<th colspan="2">Geography</th>
</tr><th rowspan="2">Art</th>
<th colspan="2">Geography</th>
<th>Tuesday</th>
<th>Maths</th>
<th>Chemistry</th>
</tr><th>Maths</th>
<th>Chemistry</th>
09:00 | 10:00 | 11:00 | |
---|---|---|---|
Monday | Art | Geography | Tuesday | Maths | Chemistry |