Reputation: 1079
Kind of a silly question, but I've been seeing things such as tbody and thead/tfoot tags in other peoples tables.
Are these required even if they're empty for good markup? Or can I just leave them out?
Upvotes: 4
Views: 2832
Reputation: 34513
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.
Upvotes: 0
Reputation: 700152
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.
Upvotes: 3
Reputation: 25060
Those tags are not required and a page would validate even without them.
Upvotes: 2
Reputation: 39602
Yes, that is proper markup. Though they are optional You can read further on the W3Schools page.
Upvotes: 0
Reputation: 4665
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>
Upvotes: 0
Reputation: 167
They aren't required, but they let you do some more advanced things with headers and footers: http://www.htmldog.com/guides/htmladvanced/tables/
Upvotes: 2