Validation (HTML5): Element 'th' cannot be nested in element 'table'

Coops picture Coops · Jun 3, 2014 · Viewed 13.2k times · Source

Given the following HTML, why do you get the error:

Validation (HTML5): Element 'th' cannot be nested in element 'table'

<table>
    <th>ID</th>
    <th>text header</th>
    <tr>
        <td>7</td>
        <td>text</td>
    </tr>
</table>

Answer

Coops picture Coops · Jun 3, 2014

You cannot have the <th> element outside of a <tr>, the following snippet is valid

<table>
    <tr>
        <th>ID</th>
        <th>text header</th>
    </tr>
    <tr>
        <td>7</td>
        <td>text</td>
    </tr>
</table>

<th> Usage context https://developer.mozilla.org/en/docs/Web/HTML/Element/th

Permitted parent elements

A <tr> element.