Why would we want to “section off” tables with the <tbody> tag?
Answer
The <tbody> tag together with the <thead> and <tfoot>tags (which you will learn about in the next two exercise) give our tables semantic meaning. These tags stand to improve the user experience in a number of ways:
enhanced screen reading experience for the visually impaired
<thead> and <tfoot> information can be shown on each page for printing
with a bit of CSS, <thead> and <tfoot> information can be seen while scrolling through long tables.
The <tbody>, <thead>, and <tfoot> tags are mainly only there to help you, the developer. Using these tags, you can easily style the header or footer differently than the actual content of the table without having to create classes for them.
The above code would give the header and the footer of all tables a dark-blue background color and bold text. This helps the user to easily distinguish the header from the content.
The developer doesn’t come into mind; the user agent is what these are aimed at.
When it knows about their existence, it can sort things out for itself, usually regardless what order we write them. The UA knows that a header comes before a body which comes before a footer. All we as developers are doing is telling the UA that these are the component parts of our table broken down into three sections.
And let’s not forget the <caption></caption> which accessiblity guidelines recommnend.
A TABLE element has four direct child sectioning elements:
caption
thead
tbody
tfoot
Under accessibility guidelines, CAPTION is required, and should be just inside the TABLE element, followed by the other three in that order. THEAD contains header information such as table title and column headings. TBODY contains the table rows and table data. TFOOT contains the boilerplate and small print such as appendix and other footnote details.
The caption is like a page title, so should describe the table in the form of a heading. You can even use <h2></h2> in the caption to show that it is a heading.
Sorry that I can’t gather all this. Can someone help with an example of how the table element can look like with all these sectioning elements applied.
Keep comments to a minimum. They can clutter things up really quick and that makes HTML harder to read, not easier. The structure and content should be able to work together to mete out enough information for the reader to get the gist of things.
If there is to be any description of the table and it contents then use the <caption></caption> element just inside the <table></table>. This is required for accessibility so make the caption brief, descriptive and concise. More information may be given in the <tfoot></tfoot> if necessary.