This tutorial aims to equip you with the skills to use table headers and footers effectively in HTML. It will provide a clear understanding of how to use the <thead>
, <th>
, and <tfoot>
elements.
<thead>
and <th>
elements.<tfoot>
element.Basic knowledge of HTML is required. Familiarity with HTML tables would be beneficial but not necessary as this tutorial will cover everything from the ground up.
In HTML, tables are a way to present data in rows and columns. Headers (<thead>
and <th>
) provide labels for the columns, while footers (<tfoot>
) can be used to summarize data or add additional information.
<thead>
and <th>
The <thead>
element is used to group the header content in an HTML table. The <th>
element defines a header cell in a table. It makes the text bold and center-aligned by default.
<tfoot>
The <tfoot>
element is used to group the footer content in an HTML table. It goes always after any <tbody>
and <tr>
elements, but before the <thead>
and <tr>
elements.
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>1234567890</td>
</tr>
</tbody>
</table>
In this example, the <thead>
element is used to create a header row for the table. Each <th>
element within the <thead>
produces a header cell.
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>1234567890</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Total Records: 1</td>
</tr>
</tfoot>
</table>
In this example, the <tfoot>
element is used to create a footer row for the table. It summarizes the number of records in the table.
In this tutorial, you learned how to create table headers using the <thead>
and <th>
elements, and how to create a table footer with the <tfoot>
element.
Continue practicing to get more familiar with these elements. Try to incorporate headers and footers in your future tables to make them more readable and structured.
For more information on HTML tables, check out the official HTML tables documentation.
Create a table with headers for "Product", "Quantity", and "Price".
Add a footer to the table from Exercise 1, summarizing the "Total Price".
<table>
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>5</td>
<td>$5</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>5</td>
<td>$5</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Total Price: $5</td>
</tr>
</tfoot>
</table>
Remember, practicing is key to mastering any concept. Keep trying different table structures to get a good grasp of these concepts.