Cambodia Anita's blog Danny's blog Photos Resources
Skip to content

Primer 4: Tables

To start with, let’s be clear that tables are for the purpose of expressing tabular data. They are not supposed to be used for the purpose of layout out alone. The reason for this is simple. Screen Readers, which are used by visually impaired people to “read” websites, cannot make sense of tables that are used for the purpose of layout alone. In other words, to be considerate to those with visual impairments, it’s important to use tables at the appropriate time and in the appropriate way.

People use tables for layout because it’s very easy to do so. Once you become familiar with the table tags, you will find building tables very easy. This is why many people, myself included, have used tables to layout graphics and text rather than using CSS/Layers.

I would write a tutorial on building tables but an excellent one has already been created which I cannot improve on. As of January 23, 2007 it can be found here. A somewhat simpler 3 part table tutorial can be found at HTML Dog: part 1, part 2, part 3.

So, instead of writing a tutorial, I thought it might be helpful to make a chart of XHTML tags related to tables.

XHTML Table Tag definitions from ww.w3schools.com
Tags Definition
<table>
Defines a table
<caption>
Defines a table caption
<th>
Defines a table header
<tr>
Defines a table row
<td>
Defines a table cell
<thead>
Defines a table header
<tbody>
Defines a table body
<tfoot>
Defines a table footer
<col>
Defines attributes for table columns
<colgroup>
Defines groups of table columns

Below is the code for the table above. Using the definitions as a reference, try to understand what is going on in the code.

<table summary=”A table listing XHTML tags that are used when working with tables” width=”50%” border=”1″ cellspacing=”0″ cellpadding=”0″>

<caption>
XHTML Table Tag definitions from <a href=”http://www.w3schools.com/tags/default.asp”>www.w3schools.com</a>
</caption>

<tr>
<th scope=”col”>Tags</th>
<th scope=”col”>
Definition</th>
</tr>

<tr>
<td><div align=”left”>
<table></div></td>
<td><div align=”left”>
Defines a table</div></td>
</tr>
<tr>
<td><div align=”left”>
<caption></div></td>
<td><div align=”left”>
Defines a table caption</div></td>
</tr>
<tr>
<td><div align=”left”>
<th></div></td>
<td><div align=”left”>
Defines a table header</div></td>
</tr>
<tr>
<td><div align=”left”>
<tr></div></td>
<td><div align=”left”>
Defines a table row</div></td>
</tr>
<tr>
<td><div align=”left”>
<td></div></td>
<td><div align=”left”>
Defines a table cell</div></td>
</tr>
<tr>
<td><div align=”left”>
<thead></div></td>
<td><div align=”left”>
Defines a table header</div></td>
</tr>
<tr>
<td><div align=”left”>
<tbody></div></td>
<td><div align=”left”>
Defines a table body</div></td>
</tr>
<tr>
<td><div align=”left”>
<tfoot></div></td>
<td><div align=”left”>
Defines a table footer</div></td>
</tr>
<tr>
<td><div align=”left”>
<col></div></td>
<td><div align=”left”>
Defines attributes for table columns</div></td>
</tr>
<tr>
<td><div align=”left”>
<colgroup></div></td>
<td><div align=”left”>
Defines groups of table columns</div></td>
</tr>
</table>

Hopefully the tutorials I referenced will make using tables a snap. Now let’s move on to the tools that will enable you to layout your site exactly the way you like it, CSS/Layers.