Categories
HTML Tutorials

Adding a footer

The tfoot element denotes the block of rows that form the footer for the table. In HTML5, you can put the ‘tfoot’ element after the tbody or the last tr element, which is more consistent with the way the table will be displayed by the browser.

The below code shows how the tfoot element can be used to create a footer for a table element.

<html>
  <head>
    <title>Example</title>
    <meta name="author" content="Adam Freeman"/>
    <meta name="description" content="A simple example"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <style>
      thead th, tfoot th { 
        text-align:left; 
        background:grey; 
        color:white
      }
      tbody th { 
        text-align:right; 
        background: lightgrey; 
        color:grey
      }
    </style>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>Rank</th>
          <th>Name</th>
          <th>Color</th>
          <th>Size</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>Favorite:</th>
          <td>Apples</td>
          <td>Green</td>
          <td>Medium</td>
        </tr>
        <tr>
          <th>2nd Favorite:</th>
          <td>Oranges</td>
          <td>Orange</td>
          <td>Large</td>
        </tr>
        <tr>
          <th>3rd Favorite:</th>
          <td>Pomegranate</td>
          <td>A kind of greeny-red</td>
          <td>Varies from medium to large</td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <th>Rank</th>
          <th>Name</th>
          <th>Color</th>
          <th>Size</th>
        </tr>
      </tfoot>
    </table>
  </body>
</html>