html
  1. html-tfoot-tag

HTML <tfoot> Tag

  • The HTML <tfoot> tag defines a set of rows that define the footer of a table.
  • The <tfoot> tag must be placed inside a <table> element, after the <thead> and <tbody> elements.

Syntax

The basic syntax for the <tfoot> tag is as follows:

<table>
  <thead>
    <!-- table header rows here -->
  </thead>
  <tbody>
    <!-- table body rows here -->
  </tbody>
  <tfoot>
    <!-- table footer rows here -->
  </tfoot>
</table>

Example

A simple example of the <tfoot> tag is as follows:

<table>
  <thead>
    <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td>john@example.com</td>
    </tr>
    <tr>
      <td>Jane</td>
      <td>Doe</td>
      <td>jane@example.com</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="3">Total records: 2</td>
    </tr>
  </tfoot>
</table>
Try Playground

Explanation

The <tfoot> element provides the functionality of defining a table footer section that contains relevant information about the table content. It is used to summarize the values of the table, display a total or other data.

When the table is rendered, the footer section is displayed in a separate division at the bottom of the table.

Use

The <tfoot> tag is used to define the footer section of an HTML table. It can be used to display a summary of the data in the table.

This tag is often used in web applications to display the number of records found, the total, the average or any other type of information that the developer wants to display.

Important Points

  • The <tfoot> tag must be used inside a <table> element.
  • The <tfoot> tag comes after the <thead> and <tbody> tags.
  • When using the <tfoot> tag, the total number of columns in the footer row should be equal to the number of columns in the table.
  • We can use the colspan attribute to make a single cell span multiple columns in the table footer.

Summary

The <tfoot> tag provides a way to add a footer to an HTML table. It is used to summarize data displayed in the table and is often used to display the number of records or a total value. Being a part of the <table> element, it allows web developers to present structured data in an easy-to-read format.

Published on: