Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 781
Coops Avatar asked Jun 03 '14 21:06

Coops


1 Answers

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

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

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

Permitted parent elements

A <tr> element.

like image 96
Coops Avatar answered Oct 27 '22 21:10

Coops