kind of a silly question, but ive been seeing things such as tbody and thead/tfood tags in other peoples tables
are these required even if they're empty for good markup? or can i just leave them out?
thanks
kind of a silly question, but ive been seeing things such as tbody and thead/tfood tags in other peoples tables
are these required even if they're empty for good markup? or can i just leave them out?
thanks
They aren't required, but they let you do some more advanced things with headers and footers: http://www.htmldog.com/guides/htmladvanced/tables/
if you really need tables, you should use them. If you use tables only for design purposes you should switch to css-markup.
A simple correct table example:
<table>
<thead>
<tr>
<td>id</td>
<td>name</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>User1</td>
</tr>
<tr>
<td>2</td>
<td>User2</td>
</tr>
</tbody>
</table>
Yes, that is proper markup. Though they are optional You can read further on the W3Schools page.
Those tags are not required and a page would validate even without them.
The table sections (thead/tbody/tfoot) are optional. The table caption (caption) and column definitons (col/colgroup) are also optional.
In HTML (but not XHTML) the closing tag for rows and cells are also optional, so you could write a table as:
<table>
<tr>
<th>1
<th>2
<tr>
<td>3
<td>4
<tr>
<td>5
<td>6
</table>
It's however recommended that you close the tags to get better structure in the code. It also makes it a lot easier if you decide to change to XHTML.
The <tbody>
tag is only partially supported in all major browsers.
Tables may have multiple bodies, but when it only has one single body, the HTML tbody tag may be safely omitted.