Table Element
The <tfoot> element represents a set of rows summarizing or providing supplementary information about the columns of a table. It typically contains totals, summaries, footnotes, or other concluding information. Like <thead>, the <tfoot> provides semantic structure that helps browsers and assistive technologies understand the table’s organization.
Interactive code playground requires JavaScript. Here's the code:
<table>
<caption>Quarterly Sales Report - 2024</caption>
<thead>
<tr>
<th scope="col">Quarter</th>
<th scope="col">Revenue</th>
<th scope="col">Expenses</th>
<th scope="col">Profit</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row">Total</th>
<td>$450,000</td>
<td>$280,000</td>
<td>$170,000</td>
</tr>
</tfoot>
<tbody>
<tr>
<th scope="row">Q1</th>
<td>$120,000</td>
<td>$75,000</td>
<td>$45,000</td>
</tr>
<tr>
<th scope="row">Q2</th>
<td>$105,000</td>
<td>$68,000</td>
<td>$37,000</td>
</tr>
<tr>
<th scope="row">Q3</th>
<td>$115,000</td>
<td>$72,000</td>
<td>$43,000</td>
</tr>
<tr>
<th scope="row">Q4</th>
<td>$110,000</td>
<td>$65,000</td>
<td>$45,000</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: right;
}
th[scope="col"], th[scope="row"] {
text-align: left;
}
thead {
background-color: #2c3e50;
color: white;
}
tfoot {
background-color: #34495e;
color: white;
font-weight: bold;
}
tbody tr:nth-child(even) {
background-color: #f8f9fa;
}
</style>
< caption > Table caption </ caption >
< th scope = " row " > Total </ th >
The <tfoot> element should appear in this specific order:
<caption> (optional)
<colgroup> (optional)
<thead> (optional)
<tfoot> (optional)
<tbody> (one or more)
The <tfoot> element supports all global HTML attributes .
Interactive code playground requires JavaScript. Here's the code:
<table>
<caption>Monthly Budget Summary</caption>
<thead>
<tr>
<th scope="col">Category</th>
<th scope="col">Budgeted</th>
<th scope="col">Actual</th>
<th scope="col">Difference</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row">Total</th>
<td>$5,000</td>
<td>$4,750</td>
<td class="positive">+$250</td>
</tr>
</tfoot>
<tbody>
<tr>
<th scope="row">Rent</th>
<td>$2,000</td>
<td>$2,000</td>
<td>$0</td>
</tr>
<tr>
<th scope="row">Utilities</th>
<td>$300</td>
<td>$275</td>
<td class="positive">+$25</td>
</tr>
<tr>
<th scope="row">Food</th>
<td>$800</td>
<td>$725</td>
<td class="positive">+$75</td>
</tr>
<tr>
<th scope="row">Transport</th>
<td>$400</td>
<td>$350</td>
<td class="positive">+$50</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: right;
}
th[scope="col"], th[scope="row"] {
text-align: left;
}
thead {
background-color: #27ae60;
color: white;
}
tfoot {
background-color: #229954;
color: white;
font-weight: bold;
font-size: 1.1em;
}
.positive {
color: #27ae60;
font-weight: bold;
}
</style>
Interactive code playground requires JavaScript. Here's the code:
<table>
<caption>Class Test Scores</caption>
<thead>
<tr>
<th scope="col">Student</th>
<th scope="col">Score</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row">Average</th>
<td>85.2</td>
</tr>
<tr>
<th scope="row">Highest</th>
<td>98</td>
</tr>
<tr>
<th scope="row">Lowest</th>
<td>72</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Alice Chen</td>
<td>92</td>
</tr>
<tr>
<td>Bob Martinez</td>
<td>85</td>
</tr>
<tr>
<td>Carol Davis</td>
<td>98</td>
</tr>
<tr>
<td>David Kim</td>
<td>72</td>
</tr>
<tr>
<td>Emma Wilson</td>
<td>79</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
td:last-child {
text-align: right;
}
thead {
background-color: #3498db;
color: white;
}
tfoot {
background-color: #e8f6f3;
border-top: 3px solid #16a085;
}
tfoot th {
font-weight: 600;
}
</style>
Interactive code playground requires JavaScript. Here's the code:
<table>
<caption>Product Specifications</caption>
<thead>
<tr>
<th scope="col">Feature</th>
<th scope="col">Value</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2">
<small>
* Tested under standard conditions<br>
** Results may vary based on usage
</small>
</td>
</tr>
</tfoot>
<tbody>
<tr>
<th scope="row">Battery Life*</th>
<td>Up to 12 hours</td>
</tr>
<tr>
<th scope="row">Weight</th>
<td>1.5 kg</td>
</tr>
<tr>
<th scope="row">Performance**</th>
<td>High</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
thead {
background-color: #8e44ad;
color: white;
}
tfoot {
background-color: #f8f9fa;
font-style: italic;
border-top: 2px solid #8e44ad;
}
tfoot small {
color: #666;
line-height: 1.6;
}
</style>
Semantic Clarity
Clearly indicates which rows contain summary or supplementary information.
Printing
Browsers can repeat the footer on each printed page for long tables.
Accessibility
Screen readers can identify and announce footer content appropriately.
Styling
Apply consistent styles to footer rows with a single CSS selector.
Fixed Footers
Create sticky footers that remain visible while scrolling.
Data Integrity
Keeps summaries and totals structurally separate from raw data.
Interactive code playground requires JavaScript. Here's the code:
<table>
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Quantity</th>
<th scope="col">Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row" colspan="2">Grand Total</th>
<td>$342.97</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Widget A</td>
<td>3</td>
<td>$59.99</td>
</tr>
<tr>
<td>Widget B</td>
<td>2</td>
<td>$99.99</td>
</tr>
<tr>
<td>Widget C</td>
<td>1</td>
<td>$23.00</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
td:nth-child(2), td:nth-child(3) {
text-align: right;
}
thead {
background-color: #2c3e50;
color: white;
}
tfoot {
background-color: #34495e;
color: white;
font-weight: bold;
font-size: 1.1em;
}
tfoot td {
font-size: 1.2em;
}
</style>
Interactive code playground requires JavaScript. Here's the code:
<table>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Sales</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row">Total Sales</th>
<td>$85,000</td>
</tr>
</tfoot>
<tbody>
<tr><td>January</td><td>$20,000</td></tr>
<tr><td>February</td><td>$25,000</td></tr>
<tr><td>March</td><td>$22,000</td></tr>
<tr><td>April</td><td>$18,000</td></tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
td:last-child {
text-align: right;
}
thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
tfoot {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
color: white;
font-weight: bold;
}
</style>
Interactive code playground requires JavaScript. Here's the code:
<table>
<caption>Invoice #12345</caption>
<thead>
<tr>
<th scope="col">Description</th>
<th scope="col">Amount</th>
</tr>
</thead>
<tfoot>
<tr class="subtotal">
<th scope="row">Subtotal</th>
<td>$100.00</td>
</tr>
<tr class="tax">
<th scope="row">Tax (10%)</th>
<td>$10.00</td>
</tr>
<tr class="total">
<th scope="row">Total</th>
<td>$110.00</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Professional Services</td>
<td>$75.00</td>
</tr>
<tr>
<td>Consultation Fee</td>
<td>$25.00</td>
</tr>
</tbody>
</table>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
td {
text-align: right;
}
thead {
background-color: #2c3e50;
color: white;
}
tfoot .subtotal {
background-color: #ecf0f1;
}
tfoot .tax {
background-color: #e8eaed;
}
tfoot .total {
background-color: #2c3e50;
color: white;
font-weight: bold;
font-size: 1.1em;
}
</style>
Create a footer that stays visible while scrolling:
Interactive code playground requires JavaScript. Here's the code:
<div class="table-container">
<table>
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="row">Total</th>
<td>$245.00</td>
</tr>
</tfoot>
<tbody>
<tr><td>Item 1</td><td>$25.00</td></tr>
<tr><td>Item 2</td><td>$35.00</td></tr>
<tr><td>Item 3</td><td>$45.00</td></tr>
<tr><td>Item 4</td><td>$55.00</td></tr>
<tr><td>Item 5</td><td>$20.00</td></tr>
<tr><td>Item 6</td><td>$30.00</td></tr>
<tr><td>Item 7</td><td>$35.00</td></tr>
</tbody>
</table>
</div>
<style>
.table-container {
max-height: 250px;
overflow-y: auto;
border: 1px solid #ddd;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
td:last-child {
text-align: right;
}
thead {
position: sticky;
top: 0;
background-color: #3498db;
color: white;
z-index: 10;
}
tfoot {
position: sticky;
bottom: 0;
background-color: #2c3e50;
color: white;
font-weight: bold;
z-index: 10;
}
</style>
Always use scope="row" for header cells in the footer:
< th scope = " row " > Total </ th >
Make sure footer content is self-explanatory:
< th scope = " row " > Grand Total (All Categories) </ th >
< th scope = " row " > Grand Total </ th >
< small > Includes all categories and applicable taxes </ small >
< th scope = " row " > Subtotal </ th >
< th scope = " row " > Shipping </ th >
< th scope = " row " > Total </ th >
< th scope = " row " > Mean </ th >
< th scope = " row " > Median </ th >
< th scope = " row " > Std. Deviation </ th >
< p >< strong > Notes: </ strong ></ p >
< li > All prices in USD </ li >
< li > Shipping not included </ li >
< li > Prices subject to change </ li >
/* Basic tfoot styling */
background-color : # f8f9fa ;
border-top : 2 px solid # 333 ;
background : linear-gradient ( to right , # 4facfe , # 00f2fe );
/* Multiple row differentiation */
background-color : # 2c3e50 ;
box-shadow : 0 -2 px 4 px rgba ( 0 , 0 , 0 , 0.1 );
/* Separation from tbody */
border-top : 3 px double # 333 ;
For long tables that span multiple pages when printed:
display : table-header-group ;
display : table-footer-group ;
display : table-row-group ;
✅ Use for summaries and totals - perfect for aggregated data
✅ Place before <tbody> in HTML source code
✅ Use <th> with scope="row" for footer labels
✅ Keep styling consistent with the rest of the table
✅ Provide clear context for summary information
✅ Consider multiple rows for complex summaries
❌ Don’t use for non-summary content - keep it relevant to the data
❌ Don’t omit for financial tables - totals are important
❌ Don’t use deprecated attributes - use CSS instead
❌ Don’t make it visually identical to tbody - differentiate it
❌ Don’t forget accessibility - use proper scope attributes
Financial Data
Perfect for displaying totals, subtotals, and grand totals in financial tables.
Statistical Tables
Show averages, medians, or other statistical summaries.
Footnotes
Add explanatory notes, disclaimers, or data source information.
Multi-page Tables
Repeat summary information on each printed page.
The <tfoot> element is supported in all browsers:
✅ Chrome (all versions)
✅ Firefox (all versions)
✅ Safari (all versions)
✅ Edge (all versions)
✅ Opera (all versions)
✅ Internet Explorer (all versions)