9 Tables

A table is a rectangular array of cells, arranged in rows and columns. To create a table in HTML we use the <table>...</table> tags. Every row of the table is enclosed in <tr>...</tr> and the data for each cell is enclosed in <td>...</td>.

<!-- HTML to generate a table of contents -->
<table>
<!-- Start the first row -->
<tr>
<!-- Start the first column entry for this row -->
<td>
Chapter 1
</td>
<!-- Start the second column entry for this row -->
<td>
<a href="introduction.html">Introduction</a>
</td>
</tr>
<!-- Start the second row -->
<tr>
<!-- Start the first column entry for this row -->
<td>
Chapter 2
</td>
<!-- Start the second column entry for this row -->
<td>
<a href="first_html.html">First HTML</a>
</td>
</tr>
</table>

This generates:

Chapter 1 Introduction
Chapter 2 First HTML

You might want the very first row and/or column of the table to contain the headings that describe the data, and to do this you use the <th>...</th> tags instead of the <td>...</td> ones.

Tables are always made large enough to accommodate all of their data. Tables can have several attributes to define how they look:

Each row and data tag can take attributes as well:

You can also use <td colspan=2> to specify that the data spans two columns rather than one.


Previous page Next page