According the HTML5 spec, th elements are not allowed to have heading elements inside of them. However, this provides a weird order in the heading map depending on the content surrounding the table.
In this case, the table topic 2 may have certain content (in the second td) which can have a subheading. To follow the heading structure previously layed out, you would expect to have to use a h3 here. But if you would later use a screenreader tool, you would miss the fact that this h3 is a subheading of table topic 2.
<h2>Lorum Ipsum</h2>
<p>Dolor sit amet, consectetur adipiscing elit.</p>
<table>
<thead>
<tr>
<th>Table topic 1</th>
<th>Table topic 2</th>
<th>Table topic 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorum ipsum...</td>
<td>
Dolor sit amet...
<h3>Table topic 2 Subheading</h3>
Consectetur adipiscing elit...
</td>
<td>Donec malesuada congue...</td>
</tr>
</tbody>
</table>
What would be the correct solution here? Use H3? Or use H4 instead, to at least signify that there is something in between, even though that "something" doesn't appear in the heading structure.
Don't skip a heading level. Heading elements (
<h2>,<h3>, etc) help define the document outline. Table heading elements<th>don't contribute to the document outline.While it's valid HTML to include heading elements within table cells, it's worth considering if there's a more appropriate alternative way to mark up that content so that the document outline doesn't bleed into the contents of a table. Without seeing your real content, it's hard to know what approach to take, but some options to consider would be: