Validation (HTML5): Element 'th' cannot be nested in element 'table'
13,916
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.
Author by
Coops
Love to code, not sure why as head, brick, wall... you know those moments! =) Anyway I think for me it's making life easier for people and problem solving really fires me up. Plus I have a habit of trying to find the best or most efficient way of doing things. Paul SOreadytohelp
Updated on June 14, 2022Comments
-
Coops almost 2 years
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>
-
Coops over 7 yearsShould have been obvious really, given the structure of HTML tables and that everything has to be in a row
-
Jeffrey Drake over 4 yearsI ran into this, and because the message didn't really say what it should have had in the parent elements (at least in the tool I was using), it wasn't immediately obvious. It should have been obvious sure, but everyone has their days.
-
Coops over 2 yearsI think in your case, you just needed to surround all your <th> elements in a row. I have updated my answer to illustrate this