HTML also provides the tables with the <thead>, <tbody>, <tfoot>, and <caption> elements. These additional elements are useful for adding semantic value to your tables and for providing a place for separate CSS styling.

When printing out a table that doesn’t fit onto one (paper) page, most browsers repeat the contents of <thead> on every page.

There’s a specific order that must be adhered to, and we should be aware that not every element falls into place as one would expect. The following example demonstrates how our 4 elements should be placed.

<table>
 <caption>Table Title</caption> <!--| caption is the first child of table |-->
  <thead> <!--======================| thead is after caption |-->
    <tr>
      <th>Header content 1</th> 
      <th>Header content 2</th>
    </tr>
  </thead>

  <tbody> <!--======================| tbody is after thead |-->
    <tr>
      <td>Body content 1</td>
      <td>Body content 2</td>
    </tr>
  </tbody>
  
  <tfoot><!--| tfoot can be placed before or after tbody, but not in a group of tbody. |-->         <!--| Regardless where tfoot is in markup, it's rendered at the bottom. |-->                                                                                                                                                                                                                                                                                               
    <tr>
      <td>Footer content 1</td>
      <td>Footer content 2</td>
    </tr>
  </tfoot>

</table>

The following example’s results are demonstrated twice–the first table lacks any styles, the second table has a few CSS properties applied: background-color, color, and border*. The styles are provided as a visual guide and is not an essential aspect of the topic at hand.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d3e8a327-630a-4ae0-b1cf-048229387615/Untitled.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a854fa62-aad7-46c6-bb77-384a8be9766c/Untitled.png

Element | Styles Applies

|———|————— | <caption> | Yellow text on black background. | <thead> | Bold text on purple background.

<tbody> | Text on blue background.<tfoot> | Text on green background.<th> | Orange borders.<td> | Red borders.