Which of the following is the correct way to structure a page:
1) h1
only in header
<header>
<h1>Site title</h1>
<nav>...</nav>
</header>
<section>
<h2>Page title</h2>
</section>
If I use h1
exclusively inside header
as the site's title, every page will have the same content for the h1
tag. That doesn't seem very informative.
2) h1
in header
and section
, for both site and page title
<header>
<h1>Site title</h1>
<nav>...</nav>
</header>
<section>
<h1>Page title</h1>
</section>
I've also seen examples of using h1
more than once, in both header
and section
tags. However, isn't it wrong to have two titles for the same page? This example shows multiple header and h1
tags http://orderedlist.com/resources/html-css/structural-tags-in-html5/
3) h1
only in section
, emphasizing the page title
<header>
<p>Site title</p>
<nav>...</nav>
</header>
<section>
<h1>Page title</h1>
</section>
Lastly, W3 seems to recommend using h1
within the main section
element, does that mean I shouldn't use it in the header
element?
Sections may contain headings of any rank, but authors are strongly encouraged to either use only h1 elements, or to use elements of the appropriate rank for the section's nesting level.
As I state in my comment and you quote in the W3C, h1 is a heading and not a title. Each sectioning element can have its own heading element(s). You cannot think of h1 as being the title of a page only but as the heading of that particular section of the page. Just like the front page of a newspaper, each article can have its own heading (or title).
Here is a good article on this.
I would recommend using
h1
throughout. Forget abouth2
throughh6
.Back in HTML4, the 6 heading levels were used to implicitly define the sections. For example,
Now with the
section
element, you can explicitly define the sections rather than having to rely on the implicit sections created by your browser reading the different heading levels. A browser equipped with HTML5 knows that everything inside asection
element gets "demoted" by one level in the doc outline. So for example asection > h1
is semantically treated like anh2
, asection > section > h1
is like anh3
, etc.What's confusing is that browsers STILL create implicit sections based on the
h2
–h6
heading levels, yet theh2
–h6
elements don't change their styles. That means that anh2
, no matter how many sections it is nested in, will still appear like anh2
(at least in Webkit). This would be confusing if yourh2
was supposed to be, say, a level-4 heading.Mixing
h2
–h6
withsection
leads to very unexpected results. Just stick withh1
only, and usesection
to create explicit sections.Furthermore, you may use the
<main>
element. This element contains only information specific to the page, and should not include content that is repeated site-wide, such as navigation links, site headers/footers, etc. There may be only one<main>
element present in the<body>
. So your solution may be as simple as this:However, don't forget accessibility concerns. According to MDN, "there are currently no known implementations of the outline algorithm in graphical browsers or assistive technology user agents." That means that a screen reader might not be able to figure out the relative importance of sections with only
<h1>
. It might need more heading levels, such as<h2>
and<h3>
.