Tag tfoot In HTML

We will look at the HTML Tag <tfoot> with examples in this post. It should meet the learning needs.

The <tfoot> tag in HTML is used to define a footer section for a table. This tag is used in combination with the <table> tag, which creates the table itself, and the <thead> and <tbody> tags, which define the header and body sections of the table, respectively.

Tag tfoot stands for Table Foot element – Here is an example of an HTML table with a <thead>, <tbody>, and <tfoot> element:

Example: 

<!DOCTYPE html> <html> <body> <table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> </thead> <tbody> <tr> <td>Data 1</td> <td>Data 2</td> <td>Data 3</td> </tr> <tr> <td>Data 4</td> <td>Data 5</td> <td>Data 6</td> </tr> </tbody> <tfoot> <tr> <td>Footer 1</td> <td>Footer 2</td> <td>Footer 3</td> </tr> </tfoot> </table> </body> </html>

Here’s an example of using the <tfoot> tag to add a footer to a table, along with some customizations with CSS:

Example: 

<!DOCTYPE html> <html> <head> <style> table { width: 80%; border-collapse: collapse; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } tfoot td { font-weight: bold; } </style> </head> <body> <h1>Product List</h1> <table> <thead> <tr> <th>Product Name</th> <th>Price</th> <th>Quantity</th> </tr> </thead> <tbody> <tr> <td>Product 1</td> <td>$10</td> <td>100</td> </tr> <tr> <td>Product 2</td> <td>$20</td> <td>200</td> </tr> <tr> <td>Product 3</td> <td>$30</td> <td>300</td> </tr> </tbody> <tfoot> <tr> <td>Total</td> <td>$60</td> <td>600</td> </tr> </tfoot> </table> </body> </html>

Here’s another example of using the <tfoot> tag to build a table footer, along with some additional capabilities:

Example: 

<!DOCTYPE html> <html> <head> <style> table { width: 80%; border-collapse: collapse; margin: 20px auto; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } </style> </head> <body> <h1>Employee List</h1> <table> <thead> <tr> <th>Employee ID</th> <th>Employee Name</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>001</td> <td>Sam Billings</td> <td>$3000</td> </tr> <tr> <td>002</td> <td>Tom Curran</td> <td>$4500</td> </tr> <tr> <td>003</td> <td>Jeffery Anderson</td> <td>$4000</td> </tr> </tbody> <tfoot> <tr> <td colspan="2">Total</td> <td>$11500</td> </tr> </tfoot> </table> </body> </html>

Here is an example of the <tfoot> tag to add a background color and align text center with CSS:

Example: 

<!DOCTYPE html> <html> <head> <style> table { width: 80%; border-collapse: collapse; margin: 20px auto; } thead, tfoot { background-color: maroon; } th, td { border: 1px solid #ddd; padding: 8px; text-align: center; } tfoot td { font-weight: normal; } </style> </head> <body> <h1>Product List</h1> <table> <thead> <tr> <th>Product ID</th> <th>Product Name</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>A001</td> <td>Apple</td> <td>$1.50</td> </tr> <tr> <td>B002</td> <td>Banana</td> <td>$2.00</td> </tr> <tr> <td>O003</td> <td>Orange</td> <td>$3.00</td> </tr> </tbody> <tfoot> <tr> <td>Total</td> <td>$6.50</td> </tr> </tfoot> </table> </body> </html>
Advice: By default, the <thead>, <tbody>, and <tfoot> elements have no impact on how the table is laid out. But you can style these items with CSS.


Tag tfoot Uses

In an HTML table, the tag <tfoot> can be applied to include footer content.

To define the various parts of a table (footer, header, body), the <tfoot> tag is applied together with the <thead> and <tbody> tags.

By using these elements, browsers can navigate the table body on their own from the header and footer. Furthermore, if a large table occupies multiple pages, the table header and footer can be displayed at the beginning and end of each.

IMPORTANT: An element with the <tfoot> attribute should contain one or more <tr> elements.

The Tag tfoot <tfoot> should always be employed as a child of a <table> element, follows any <caption> , <colgroup>, <thead>, and <tbody> tags.

Here are some common uses of the <tfoot> tag:

  • The footer section is often used to display totals for columns or rows in the table. For example, if you have a table of sales data, you might use the <tfoot> tag to display the total sales for each month.
  • You might also use the footer section to display averages for columns or rows in the table. For example, if you have a table of student grades, you might use the <tfoot> tag to display the average grade for each assignment.
  • The footer section can be used to provide a summary of the data in the table. For example, if you have a table of survey results, you might use the <tfoot> tag to display a summary of the responses.
  • The footer section can also be used to provide additional information related to the data in the table. For example, if you have a table of products, you might use the <tfoot> tag to include a copyright notice or a link to more information about the products.

Attributes

Global

The Tag Tfoot <tfoot> also accepts the Global Attributes in HTML.

Event

The Tag Tfoot <tfoot> includes the Event Attributes in HTML.


Browser Compatibility

Element
<tfoot>YesYesYesYesYes

Predefined CSS

Majority of the browser render the <tfoot> tag with these default values:

tfoot {
display: table-footer-group;
vertical-align: middle;
border-color: inherit;
}

Tag tfoot Advantages

Here are some of the main advantages:

  • By using the <tfoot> tag to structure table data, developers can improve the accessibility of their web pages for users who rely on assistive technologies. For example, screen readers can use the <tfoot> tag to read out the footer information, providing a more complete picture of the data presented in the table.
  • The <tfoot> tag can help to improve the readability of tables by providing clear breaks between the header, body, and footer sections of the table. This makes it easier for users to scan and interpret the data in the table, and can improve the overall user experience.
  • The <tfoot> tag can also help to better organize the data in a table, particularly when it comes to displaying totals, averages, or other summary information. This makes it easier for users to understand the data presented in the table and to draw insights from it.
  • By using the <tfoot> tag consistently across a website, developers can create a more consistent user experience, which can help to improve user engagement and satisfaction.
  • By using the <tfoot> tag, developers can more easily apply styling to the footer section of a table, helping to create a more polished and professional look and feel.
If this article was informative enough to fulfill your educational needs, do share this meaningful information with your friends by clicking on the links below.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *