H1, H2, H3, H4, H5, H6 inside table TH tags? - HTML
Asked Answered
P

4

25

Can i use H1, H2, H3, H4, H5, H6 inside the table TH tags? - HTML

I tryed to validate with the w3 validator, but it doesn't validate. I get this:

The element h4 must not appear as a descendant of the th element.
<th><h4>Orange</h4></th>

I use HTML5, so i think that the best idea is to use <div> to make a table and then put the <H4> tags in it. Or is this a bad idea too? Because then it looks something like this:

<h4>first title</h4> <h4>second title</h4> <h4>third title</h4> 
<p>first parahraph</p> <p>second parahraph</p> <p>third parahraph</p>

And i don't know how this looks, 3 heading tags that close, without any text or paragraphs between that.

Pancake answered 8/8, 2012 at 7:26 Comment(3)
@tastro - If your data can be appropriately represented in table form, why can't you just use the th element and style it as you need. Why bother with the header elements?Lifeless
You can put header tags inside a <td>, and you can use <td> in the same places that <th> is allowed. So your example works if you change it to <td><h4>Orange</h4></td>. It's still probably a better idea to put tabular data in a table and just style the <th> elements appropriately, but this might be useful as a workaround for anyone searching this in the future.Duchess
Back then, when i posted this question, i was using table for design. This is not the way a table should be used. I know that now. :)Pancake
L
39

The HTML living standard explicity forbids this. The th element content model is as follows (emphasis added):

Flow content, but with no header, footer, sectioning content, or heading content descendants.

"Heading content" refers to the h1, h2 etc. elements, as well as the hgroup element:

Heading content defines the header of a section (whether explicitly marked up using sectioning content elements, or implied by the heading content itself).

h1 h2 h3 h4 h5 h6 hgroup

Lifeless answered 8/8, 2012 at 7:35 Comment(1)
I got the same on w3 validator. So i think that this is correct. Thank you.Pancake
I
-8

In terms of valid HTML? Yes.

In terms of it being a good idea? Yes - these are heading areas and such are good candidates for a H tag.

There is a school of thought that you shouldn't use one tag merely to enclose another, so you could argue the heading text should sit directly in the th. However from an SEO perspective it is the H tag that is more important, so you frequently see this sort of thing:

<th><h3>Some heading</h3></th>
Insnare answered 8/8, 2012 at 7:31 Comment(0)
S
-8

Yes, but TH means table header, I think header in table header is not good for semantic. Maybe it good for SEO.

Sidetrack answered 8/8, 2012 at 7:32 Comment(0)
I
-8

Yes .You can use the H1 , H2,.. H6 Tags inside the Table TH tags. These will do the same functionality in the table TH tag too. The text size of the table contents can be changes accordingly you needs.

Just see this link for the reference.

Inhabit answered 8/8, 2012 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.