HTML <tfoot> Tag โ Table Footer Section
๐ Introduction
The <tfoot> tag is used to define the footer section of a table.
It is typically used for:
- Totals (sum of values)
- Summary information
- Notes or results
It works together with:
<thead>โ header<tbody>โ main data<tfoot>โ footer
๐งฑ Syntax
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Product A</td>
<td>100</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>100</td>
</tr>
</tfoot>
</table>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>TFOOT Example</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Book</td>
<td>50</td>
</tr>
<tr>
<td>Pen</td>
<td>10</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>60</td>
</tr>
</tfoot>
</table>
</body>
</html>
๐ฅ๏ธ Output Explanation
<thead>shows column titles<tbody>shows data rows<tfoot>shows summary (like total price)
๐ฏ Why <tfoot> is Important
1. ๐ Used in Reports
- Sales totals
- Financial summaries
- Data analysis tables
2. ๐ง Clear Structure
Separates:
- Data (tbody)
- Summary (tfoot)
3. โ๏ธ Browser Behavior
Some browsers:
- Keep footer visible while scrolling large tables
๐งฉ Full Table Structure
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>yourName</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>End of Table</td>
</tr>
</tfoot>
</table>
โ๏ธ Table Sections Overview
| Tag | Purpose |
|---|---|
<thead> |
Column headers |
<tbody> |
Main data |
<tfoot> |
Summary/footer |
๐จ Styling Example
<tfoot style="background-color:#ddd; font-weight:bold;">
<tr>
<td>Total</td>
<td>60</td>
</tr>
</tfoot>
๐ซ Common Mistakes
- Forgetting
<tbody>when using<tfoot>โ - Putting data inside
<tfoot>โ - Mixing structure randomly โ
๐งช Mini Exercise
Create a table with:
<thead>for product names and prices<tbody>with at least 3 products<tfoot>showing total price- Style the footer differently
๐ Next Step
Next lesson: The <form> tag โ how to create interactive user input forms (very important for real websites).