'div' inside 'table'

Is a div inside a table allowed or not according to W3C?


Solution 1:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <title>test</title>
  </head>
  <body>
    <table>
      <tr>
        <td>
          <div>content</div>
        </td>
      </tr>
    </table>
  </body>
</html>

This document was successfully checked as XHTML 1.0 Transitional!

Solution 2:

You can't put a div directly inside a table, like this:

<!-- INVALID -->
<table>
  <div>
    Hello World
  </div>
</table>

Putting a div inside a td or th element is fine, however:

<!-- VALID -->
<table>
  <tr>
    <td>
      <div>
        Hello World
      </div>
    </td>
  </tr>
</table>

Solution 3:

You can put div tags inside a td tag, but not directly inside a table or tr tag.

Examples:

This works:

<table>
  <tr>
    <td>
      <div>This will work.</div>
    </td>
  </tr>
<table>

This does not work:

<table>
  <tr>
    <div> this does not work. </div>
  </tr>
</table>

Nor does this work:

<table>
  <div> this does not work. </div>
</table>