The <thead>, <tbody> and <tfoot> elements split an HTML table into a header group, one or more body groups and a footer group. Each one wraps a set of <tr> rows, so the browser, CSS and assistive technology can tell column headings and totals apart from the real data. The html thead tbody tfoot trio is optional for rendering, but it is the correct structure for any table longer than a few rows.
You already know that a table is built from <table>, <tr>, <th> and <td>. Row groups add one more layer between the table and its rows, and that layer gives you styling hooks, better accessibility and the option to print the header on every page.
A table can contain these direct children besides captions and column groups:
| Element | Purpose | How many allowed |
|---|---|---|
<thead> | Column headings | At most one |
<tbody> | Main data rows | One or more |
<tfoot> | Summary rows such as totals | At most one |
Each group holds only <tr> elements. The cells inside the rows are still <th> or <td>. The groups do not change how many columns the table has; they only label sets of rows.
The example below shows a small sales report. The header names the columns, the body lists the data and the footer adds a total.
The browser draws the header first, then the body rows, then the footer. The table looks the same as one made of bare <tr> elements until you add CSS, but the structure is now explicit.
In HTML 4 the <tfoot> had to appear before <tbody> so that a browser could draw the footer before loading a very long body. The current HTML living standard allows <tfoot> after the <tbody> elements, and that is the order you should write because it matches reading order. Screen readers and browsers still treat it as the footer wherever it sits in the table.
The order that the standard allows is: optional <caption>, optional <colgroup> elements, optional <thead>, then zero or more <tbody> elements (or plain <tr> rows), then optional <tfoot>.
A table can have several <tbody> elements. Use them to group related rows, for example one group per region or per category.
Every group can be styled on its own, for example with a border above each <tbody> to separate the sections visually.
Because the groups are real elements, you can target them directly.
Without the groups you would need extra classes on the rows. A selector such as tbody tr:nth-child(even) also keeps zebra striping from colouring the header row.
Row groups give a few practical benefits:
<thead> and <tfoot> on every printed page.position: sticky on thead th.table.tBodies, table.tHead and table.tFoot give direct access to each group, which makes sorting only the body rows simple.If you leave out <tbody> in your source, the HTML parser inserts one automatically around loose <tr> rows. That is why DevTools often shows a <tbody> you never wrote, and why a CSS child selector such as table > tr fails to match.
<td> or <tr> directly inside <table> and expecting no <tbody>; the parser adds it.<thead> or <tfoot>; only one of each is valid.<tr> rows and <tbody> elements in the same table; use one style.<thead> to fake layout. Tables are for tabular data, so use CSS grid or flexbox for page layout.<tbody> when it is really a footer; use <tfoot> so the meaning is clear.No. A table renders without them, and the parser adds a <tbody> for you. They are still recommended because they carry meaning and make styling and scripting easier.
Yes. You can have as many <tbody> elements as you need to group rows. Only <thead> and <tfoot> are limited to one each.
Not in current HTML. The old HTML 4 rule required it, but the living standard lets <tfoot> come after the body, which is the natural reading order.
Yes. Row headers are written as <th scope="row"> in the body, as in the sales example. Not every <th> belongs in <thead>.
Use <thead> for column headings, one or more <tbody> elements for data and <tfoot> for totals. Each group contains only <tr> rows and does not change the column count. The structure improves printing, CSS hooks, scripting and accessibility, and the parser always supplies a <tbody> if you leave it out.