HTML - <tfoot> Tag



The <tfoot> tag is used to group footer content in an HTML table. HTML <tfoot> tag is used as a child element of the HTML table (<table>).

The <tfoot> tag is frequently utilised to show column totals and can be used to summarise the columns in a table. Traditionally, the <tfoot> tag would be styled with CSS to draw attention to the column totals. By default, the <thead>, <tbody>, and <tfoot> elements have no impact on how the table is organised. However, you can style these elements with CSS.

Syntax

<tfoot>...</tfoot>

Attribute

HTML tfoot tag supports Global and Event attributes of HTML. Bellow mentioned attributes are deprecated so use CSS properties rather using these attributes.

Attribute Value Description
align left
right
center
justify
Specifies the alignment of text content(Deprecated).
bgcolor color Specifies the background color of each column cell(Deprecated).
char character Specifies the alignment of the content to a character of each column cell(Deprecated).
charoff number Specifies the number of characters to offset the column cell content from the alignment character specified by the char attribute(Deprecated).
valign baseline
bottom
middle
top
Specifies the vertical alignment of each column cell(Deprecated).

Examples of HTML tfoot Tag

Bellow examples will illustrate the usage of tfoot tag. Where, when and how to use tfoot tag and how to style the footer part of a table.

Creating Table Footer

Following is an example where we are going to use the <tfoot> tag in the HTML table.

<!DOCTYPE html>
<html>
<body>
   <table border="1">
   <thead>
      <tr>
         <th>Students</th>
         <th>English Marks</th>
         <th>Hindi Marks</th>
      </tr>
   </thead>
   <tfoot>
      <tr>
         <th colspan="3">Juliet - the best Performer!</th>
      </tr>
   </tfoot>
   <tbody>
      <tr>
         <td>John</td>
         <td>28</td>
         <td>25</td>
      </tr>
      <tr>
         <td>Peterson</td>
         <td>25</td>
         <td>25</td>
      </tr>
      <tr>
         <td>Juliet</td>
         <td>29</td>
         <td>29</td>
      </tr>
   </tbody>
   </table>
</body>
</html>

Styling Table Footer

Consider another scenario where we are going to use the <tfoot> tag in the table and apply CSS to it.

<!DOCTYPE html>
<html>
   <style>
      tfoot {
         background-color: #3f87a6;
      }
   </style>
<body>
   <table border="1">
      <thead>
         <tr>
            <th>Items</th>
            <th>Price</th>
         </tr>
      </thead>
   <tfoot>
      <tr>
         <th>Total</th>
         <th>75</th>
      </tr>
   </tfoot>
   <tbody>
      <tr>
         <td>5-Star</td>
         <td>10</td>
      </tr>
      <tr>
         <td>Dairy-Milk</td>
         <td>45</td>
      </tr>
      <tr>
         <td>KitKat</td>
         <td>20</td>
      </tr>
   </tbody>
   </table>
</body>
</html>

Align Table footer Element

Let’s consider the following example, where we are going to align the content inside the <tfoot> tag to the right side using CSS.

<!DOCTYPE html>
<html>
   <style>
      table,
      th,
      td {
         border: 1.5px solid #DE3163;
      }
   </style>
<body>
   <table style="width:50%">
      <tr>
         <th>Students</th>
         <th>Gathered Amount</th>
      </tr>
      <tr>
         <td>Ram</td>
         <td>$200</td>
      </tr>
      <tr>
         <td>Suresh</td>
         <td>$800</td>
      </tr>
      <tr>
         <td>Maya</td>
         <td>$500</td>
      </tr>
      <tfoot style="text-align:right">
         <tr>
            <td>Total</td>
            <td>$1500</td>
         </tr>
         </tfoot>
   </table>
</body>
</html>

Vertical Alignment of Table Footer Element

In the following example, we are going to use the vertical align property and make the content inside the <tfoot> tag align in the middle.

<!DOCTYPE html>
<html>
   <style>
      table,
      th,
      td {
         border: 1.5px solid #82E0AA;
      }
   </style>
<body>
   <table style="width:40%">
      <tr>
         <th>ID</th>
         <th>Employee</th>
      </tr>
      <tr>
         <td>12234</td>
         <td>Maya</td>
      </tr>
      <tr>
         <td>12235</td>
         <td>John</td>
      </tr>
      <tr>
         <td>12236</td>
         <td>Kevin</td>
      </tr>
      <tfoot style="vertical-align:middle">
         <tr style="height:100px">
            <td>Total Employees</td>
            <td>3</td>
         </tr>
      </tfoot>
   </table>
</body>
</html>

Supported Browsers

Tag Chrome Edge Firefox Safari Opera
tfoot Yes Yes Yes Yes Yes
html_tags_reference.htm
Advertisements