Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XHTML thead, tfoot and tbody importance

Tags:

xhtml

Does XHTML have an 'opinion' regarding the use of <thead>, <tfoot> and <tbody>?

Is there a case where they should be used?

Thank you.

like image 624
Francisc Avatar asked Sep 28 '10 22:09

Francisc


3 Answers

They allow you to add semantics to your table, and also allow you to style the head and the foot of the table without introducing redundant classes/ids.

I can't think of a situation where you have to use it, although I know some jQuery plugins use the head & foot to control behaviors.

If your tabular data needs headings and summary rows, use them, if not don't

like image 167
Glenn Slaven Avatar answered Nov 05 '22 16:11

Glenn Slaven


The thead, tbody, and tfoot elements in HTML are used to group table rows into logical sections based on their content. There are two main reasons you'd want to do this:

  • To allow the body to be scrolled independently of the header and/or
    footer
  • To make it easier to apply different style rules to the different sections of the table.

as stated here What is benefit of <thead>

If you are using tables to make layout then don't use these. If you are showing tabular data then use it.

And if you don't have anything to put in tfoot then don't add this.

You will find some good answers here also What is benefit of <thead>

like image 6
Jitendra Vyas Avatar answered Nov 05 '22 17:11

Jitendra Vyas


The only rules, that I'm aware of, is that the thead (if used) must be defined first, and the tfoot (if used) before the tbody (somewhat counter-intuitive, to my mind, but them's the rules).

I think that the purpose of thead is partially for print purposes, allowing columns printed on a second page to have the thead repeated, in order that the data makes more sense.

In theory it could also allow for a scrolling tbody in the case of long tables, with fixed headers:

This division enables user agents to support scrolling of table bodies independently of the table head and foot. When long tables are printed, the table head and foot information may be repeated on each page that contains table data.

Source: http://www.w3.org/TR/html401/struct/tables.html#edef-TFOOT

This does not, however, work currently (without using at least two tables, I think).

The largest benefit, though, as @Glenn Slaven notes, seems to be semantic.

like image 5
David Thomas Avatar answered Nov 05 '22 15:11

David Thomas