HTML Reference ยท Tables
The <tbody> element
Reference for the HTML <tbody> element: grouping the main rows of a table, using several bodies, the implied tbody the parser adds, and technical details.
The <tbody> element groups the rows that form the body of a <table>: the actual data, as opposed to the column headings in <thead> and the totals or notes in <tfoot>.
A table can have several <tbody> elements. Each one is a separate group of rows, which is useful when the data falls into sections.
<table> <thead>...</thead> <tbody> <tr>...</tr> <tr>...</tr> </tbody> </table>
Try it
Each <tbody> starts with a header cell using scope="rowgroup", so it labels every row in its own group.
Attributes
This element has no attributes of its own. It accepts the global attributes. The obsolete align, valign, char, charoff and bgcolor attributes should be replaced with CSS (text-align, vertical-align, background-color).
Usage notes
- There is always a tbody. If you write
<tr>elements directly inside<table>, the HTML parser inserts a<tbody>around them. That's whytable > trnever matches in CSS orquerySelector; usetable trortbody > tr. - Several bodies, one structure. Use multiple
<tbody>elements for sections of data that share the same columns. If the sections have different columns, they probably belong in separate tables. - Scripting.
table.tBodiesreturns all bodies, andtable.createTBody()adds a new one after the last existing body. - Long tables. Some interfaces scroll only the body while the head stays visible. You can do this with
position: stickyon the header cells.
Technical summary
| Content categories | None |
| Permitted content | Zero or more <tr> and script-supporting elements |
| Tag omission | The start tag can be omitted if the first thing inside is a <tr> and the element is not directly after a <tbody>, <thead> or <tfoot> whose end tag was omitted (it can't be omitted if the element is empty). The end tag can be omitted if it is immediately followed by a <tbody> or <tfoot>, or if there is no more content in the parent |
| Permitted parents | A <table>, after any <caption>, <colgroup> and <thead> elements, and only if the table has no <tr> children of its own |
| Implicit ARIA role | rowgroup |
| DOM interface | HTMLTableSectionElement |
| Default display | table-row-group |
Browser support
Supported in every browser.
Related
<thead>โ the header rows<tfoot>โ the footer rows<tr>โ a table row- Lesson: Tables
- Lesson: Table Headers, Sections and Captions