Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a <tr> have to be inside a <tbody>

Does a table row (<tr>) have to be in a table body (<tbody>), if the table has a table body, or can it exist outside of the table body?

<table>
    <tr>
      <td colspan='2'>...</td>
    </tr>

    <tbody>
      <tr>
        <td>...</td>
        <td>...</td>
      </tr>
    </tbody>

    <tr>
      <td colspan='2'>...</td>
    </tr>

    <tbody>
      <tr>
        <td>...</td>
        <td>...</td>
      </tr>
    </tbody>

</table>
like image 383
superUntitled Avatar asked May 03 '11 16:05

superUntitled


2 Answers

Contrary to what Terrill Thomson said, a table with <tr> tags outside of the <thead>, <tfoot> and <tbody> tags but inside the <table> tags will validated against the W3C Markup Validation Service.

This document was successfully checked as HTML 4.01 Transitional:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
  <head>
  </head>
  <body>
    <table>
      <thead>
        <th colspan="2">head1</th>
        <th>head2</th>
      </thead>
      <tfoot>
        <th colspan="2">foot1</th>
        <th>foot2</th>
      </tfoot>

      <tr><td colspan="3">this row is outside of thead and tfoot</td></tr>

      <tbody>
        <tr>
          <td>1-1</td>
          <td>1-2</td>
          <td>1-3</td>
        </tr>
        <tr>
          <td>2-1</td>
          <td>2-2</td>
          <td>3-3</td>
        </tr>
        <tr>
          <td>3-1</td>
          <td>3-2</td>
          <td>3-3</td>
        </tr>
      </tbody>
  </body>
</html>
like image 65
zielot Avatar answered Oct 06 '22 01:10

zielot


No, the <tr> can be in the <thead>, <tbody>, <tfoot> or it doesn't have to be in any of them.

like image 39
Brook Julias Avatar answered Oct 06 '22 01:10

Brook Julias