
During our last instalment of this series, we began talking about organizational tables. This time around, we’ll be discussing some of the more advanced portions on tables in HTML.
If you’re using a table to organize data, you’ll likely have column headers that identify the type of data contained within that column. Using what we’ve previously covered, you could simply use a tr at the beginning of the table and use CSS to stylize them. However, there is a better way.
HTML contains a method to specify a table header, footer and body. We can use this method by wrapping the appropriate rows in thead, tfoot and tbody tags, respectively. In the thead section, cells must use th instead of td. The order of these “groups” is also vital. The thead and tfoot groups must be before the tbody group (the footer will be still appear below the body).
This method has a number of advantages over simply ordering your rows to create a header and footer. For starters, these three tags provide semantic meaning to your table. Having the footer above the body, in the code, allows the browser to render the footer before the (potentially long) body has loaded. Additionally, when you’re generating your body via a programming language (such as PHP), having the (likely) static header and footer before your dynamic body code will be neater.
Example:
[html]<table>
<thead>
<tr>
<th>ID</th>
<th>Surname</th>
<th>First Name</th>
<th>Email</th>
</tr>
</thead>
<tfoot>
<tr>
<td>ID</td>
<td>Surname</td>
<td>First Name</td>
<td>Email</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>192<td>
<td>Smith</td>
<td>John</td>
<td>john.smith@example.com</td>
</tr>
<tr>
<td>193</td>
<td>Doe</td>
<td>Jane</td>
<td>jdoe282@example.com</td>
</tr>
</tbody>
</table>[/html]





used tires
November 8, 2009 12:51 pm
That’s interesting, I’ve been coding tables and and HTML for a while, but I’ve never used the thread code nor the tfoot code, I guess mainly because I’ve never known about them =D I suppose it applies to many people.
Till then,
Jean
Biannka
November 15, 2009 2:09 pm
I first used thead at work during a redesign task for a client. tfoot is something I never used as well as many other table related tags that goes unnoticed.