Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it required to use thead, tbody and tfoot tags?

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?

like image 568
FrozenHeart Avatar asked Mar 17 '15 23:03

FrozenHeart


People also ask

Is thead and tbody required?

No. Modern browsers will add these by default.

What is the use of thead tbody and Tfoot?

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.

What is the difference between the thead tbody and Tfoot?

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.

Can Tfoot be before Tbody?

According to the W3 specs, tfoot has to come before tbody .


2 Answers

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

Table of data

like image 175
whoacowboy Avatar answered Nov 13 '22 08:11

whoacowboy


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 any caption, colgroup, and thead elements, but only if there are no tbody 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.

like image 39
Arwym Avatar answered Nov 13 '22 09:11

Arwym