Should I really use thead
, tbody
and tfoot
tags every time that I use a table
tag? Is it required by the standard or not?
No. Modern browsers will add these by default.
The <thead> tag is used to group header content in an HTML table. The <thead> element is used in conjunction with the <tbody> and <tfoot> elements to specify each part of a table (header, body, footer). Browsers can use these elements to enable scrolling of the table body independently of the header and footer.
thead is used to enclose a group of rows in a table as a header. tfoot is used to enclose a group of rows in a table as a footer, such as last row for summary. tbody is for main body of the table.
According to the W3 specs, tfoot has to come before tbody .
Those tags are not required. It is considered good form to use them if the table is used to represent data, which is what a table should be used for. If a table is used for laying out content they are typically omitted.
W3C
The tabular data spec for HTML5 does not require them:
Contexts in which this element (
tr
) can be used:
- As a child of a
thead
element.- As a child of a
tbody
element.- As a child of a
tfoot
element.- As a child of a
table
element, after anycaption
,colgroup
, andthead
elements, but only if there are notbody
elements that are children of the table element.
Even though I believe it is a good practice to section your rows within thead
, tbody
and tfoot
tags as it makes the table's rows easier to identify.
In the end, the browser will always add at least the tbody
for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With