Consent

This site uses third party services that need your consent.

Skip to content
Steven Roland

Tfoot Element: Table Footer Section

The <tfoot> HTML element is used to group the footer content in a table. It is a semantic element that helps organize and structure the rows of data that serve as the footer of the table, separating them from the header (<thead>) and body (<tbody>) sections. The <tfoot> element is particularly useful for summarizing data, providing totals, or including any other information that should appear at the bottom of the table.

Usage and Characteristics

The <tfoot> element contains one or more <tr> (table row) elements, each of which can contain <td> (table data) or <th> (table header) elements. It is typically used to display summary information, such as totals or other aggregate data, and should be placed after the <thead> and before the <tbody> in the HTML markup, although it is visually rendered at the bottom of the table. Here is an example of how the <tfoot> tag can be used:

<table>
  <thead>
    <tr>
      <th>Item</th>
      <th>Quantity</th>
      <th>Price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Apples</td>
      <td>10</td>
      <td>$1.00</td>
    </tr>
    <tr>
      <td>Bananas</td>
      <td>5</td>
      <td>$0.50</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Total</td>
      <td>15</td>
      <td>$1.50</td>
    </tr>
  </tfoot>
</table>

Valid Attributes for <tfoot>

The <tfoot> element does not have specific attributes beyond the global attributes, which include:

Attribute Description
class Specifies one or more class names for the element, used for CSS styling.
id Defines a unique identifier for the element, useful for linking and JavaScript.
style Contains inline CSS styles for the element.
title Provides additional information about the element, often displayed as a tooltip.

Benefits and Considerations

  • Semantic Structure: The <tfoot> element provides semantic meaning by indicating that the enclosed content is the footer of the table, which helps both users and search engines understand the structure of the table.

  • Styling and Scripting: Using <tfoot> allows developers to target the footer of the table specifically for styling and scripting, making it easier to apply styles or manipulate footer rows with JavaScript.

  • Accessibility: Proper use of the <tfoot> element, along with <thead> and <tbody>, enhances accessibility by providing a clear structure that is easily interpreted by screen readers and other assistive technologies.

In summary, the <tfoot> element is a key component for structuring and organizing the footer content of a table. It enhances semantic clarity, accessibility, and the ability to style and script table content effectively. By using the <tfoot> element, developers can create well-structured and easily manageable tables in HTML documents.