HTML <tbody> tag

The <tbody> tag is used to specify what part of a table is the body. Should be used together with the <thead> tag (for table header) and the <tfoot> tag (for table footer).

Attributes

Attribute Description Possible values
align Sets the horizontal alignment of the content in a table header left, center, right, justify, char
char Specifies a character to which the content in the table header will be aligned to theChar
charoff Specifies the number of characters the content in a table header will be aligned from the character set with the char attribute numCharacters
valign Sets the vertical alignment of the content in a table header baseline, bottom, middle, top

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

NOTE: The table footer must be declared before the table body like in the example below. This is so that web browsers can process the footer before processing the data in the table body.

<!-- styles for the different table sections --> table thead {background-color: #aaa8f0;} table tbody {background-color: #fff7d1;} table tfoot {background-color: #def5e5;} <table border="2" cellspacing="4" cellpadding="4"> <thead> <tr><th>Item</th><th>Price</th></tr> </thead> <tfoot> <tr><td>Total:</td><td>35.00</td></tr> </tfoot> <tbody> <tr><td>Lamp</td><td>12.00</td></tr> <tr><td>Watch</td><td>20.00</td></tr> <tr><td>Notebook</td><td>3.00</td></tr> </tbody> </table>
Output:
ItemPrice
Total:35.00
Lamp 12.00
Watch 20.00
Notebook 3.00

Tips & notes

Just placing the <thead>, <tbody>, and <tfoot> tags in a table will not affect the table's appearance, but this can be done using CSS to set styles for each of these tags.

Use tables when you want to display data in a tabular fashion (like a spreadsheet). For example, if you have a list of students names and you want to display their scores on 5 different tests. You can use the student names together with the subject the test was for as headings in the table, and the grades as regular tables cells.

Don't use tables to layout the contents of a webpage! This was the old technique of laying out webpages until better techniques using CSS were put into practice. Using tables for page layout will result in slower loading, less search engine friendly, less flexible pages that will be confusing to edit (think of all the nested tables), and will sometimes require workarounds to make things look right (those familiar with page layout using tables are probably thinking of spacer gifs right now!)

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation