Is nesting a h2 tag inside another header h1 tag semantically wrong?
<h1 class="fixed">
<h2 class="absolute">
Absolute Div
</h2>
</h1>
“Semantically wrong” is largely a matter of opinion (“semantics” means “relating to meaning”, but what would be the meaning here?), but the construct isn’t even syntactically (formally) correct. According to all HTML specifications and drafts, an h1
element must not contain an h2
element.
As regards to markup for a “subheading”, or a secondary part of a heading, there have been heavy debates on it, especially as regards to the proposed hgroup
element (which would let you use h1
followed by h2
as if it were a single heading). The practical approach has been, and still is, to use markup like
<h1 class="fixed">
Primary heading text<br>
<small class="absolute">
Secondary heading text
</small>
</h1>
I have preserved your class names here, but they suggest that perhaps you should not be using heading elements at all. The h1
element is supposed to be the overall heading for the page, and an h2
element is supposed to be a heading at the next lower level, for a top-level section of the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With