HTML Guide for th
A <table> contains an incoherent number of cells on one of its columns. Check the structure of the table to find the invalid column.
Example of a valid table that defines in its header that the first column is 2 cells wide:
<table>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
<tr>
<td>The table body</td>
<td>with two columns</td>
</tr>
</tbody>
</table>
This same table with an empty body will be invalid because the table header cannot match any body columns:
<table>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
The <th> HTML element defines a cell as a header of a group of table cells, and must appear within a <tr> element.
In the following example for a simple table, the first <tr> contains two <th> header cells naming the values for each column:
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Liza</td>
<td>49</td>
<tr>
<tr>
<td>Joe</td>
<td>47</td>
</tr>
</table>
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h1>Revenue</h1></th> <!-- Incorrect placement of h1 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h1>Revenue per month</h1>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h1 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h2>Revenue</h2></th> <!-- Incorrect placement of h2 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h2>Revenue per month</h2>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h2 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h3>Revenue</h3></th> <!-- Incorrect placement of h3 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h4>Revenue per month</h4>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h3 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h4>Revenue</h4></th> <!-- Incorrect placement of h4 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h4>Revenue per month</h4>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h4 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h5>Revenue</h5></th> <!-- Incorrect placement of h5 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h5>Revenue per month</h5>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h5 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.
To fix the W3C HTML Validator issue stating that a heading element like h1, h2, h3, h4, h5 or h6 must not appear as a descendant of the th element, you need to ensure that the HTML structure follows the specifications where a heading element (h1 to h6) is not placed within a table cell element like th.
Here’s an example of what might be causing the issue and how you can correct it:
Incorrect HTML:
<table>
<tr>
<th>Month</th>
<th><h6>Revenue</h6></th> <!-- Incorrect placement of h6 inside th -->
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
Corrected HTML:
<h4>Revenue per month</h4>
<table>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
<tr>
<td>January</td>
<td>$500</td>
</tr>
</table>
In the corrected example, the issue is fixed by removing the h6 element from the th element. If you need to style the text inside the th element differently, you can achieve that via CSS without nesting heading elements inside table cell elements.