Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is nesting a h2 tag inside another header with h1 tag semantically wrong?

Tags:

html

Is nesting a h2 tag inside another header h1 tag semantically wrong?

 <h1 class="fixed">
    <h2 class="absolute">
        Absolute Div
    </h2>
</h1>
like image 323
iJade Avatar asked Jun 28 '13 11:06

iJade


1 Answers

“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.

like image 85
Jukka K. Korpela Avatar answered Dec 12 '22 14:12

Jukka K. Korpela