Is it fine to use multiple <header> and in HTML 5, if yes then isn't semantically incorrect and won't it confuse mobile readers?
I saw many site uses like
<body class="home">
<header class="hd1">
<hgroup>
<h1>HTML5 Documnet</h1>
<h2>tagline</h2>
</hgroup>
</header><!-- .hd1 -->
<div class="main">
<section class="hs1">
<header>
<h1>This is a Page Sub Title</h1>
</header>
<p>Some content...</p>
<h2>Demonstrating EM and STRONG</h2>
<p><strong>This text will have more importance (SEO-wise and contextually)</strong></p>
<footer>
<p>Author: <cite>Louis Lazaris</cite></p>
</footer>
</section>
</div><!-- .main -->
<footer class="f1">
<p>copyright © year</p>
</footer><!-- .f1 -->
</body>
Yes, multiple <header> and <footer> elements are fine. They aren't used the same as <div id="header"> as most people use them for. Technically speaking, header and footer represent a header and footer of a section. A section being a piece of the page such as an article that contains header tags like <h1> and then content, then footer stuff like copyrights, citations, references, etc.
From the horses mouth:
A header element is intended to usually contain the section's heading
(an h1–h6 element or an hgroup element), but this is not required. The
header element can also be used to wrap a section's table of contents,
a search form, or any relevant logos.
And
The footer element represents a footer for its nearest ancestor
sectioning content or sectioning root element. A footer typically
contains information about its section such as who wrote it, links to
related documents, copyright data, and the like.
Directly from the spec at: http://dev.w3.org/html5/spec/Overview.html
Note that as I said these are not used to create sections like people did with <div id="header/footer"> it mentions this confusion in the spec:
The footer element is not sectioning content; it doesn't introduce a
new section.
So, again, "technically" speaking, that last footer you have there introduces a new section and isn't semantic. From the spec's point of view anyways.
Related
I've been trying for a while now to figure out how to use semantic elements to get a clean document outline for a web page of any kind. There are still some uncertainties that keep me busy.
In the attempt, I essentially used section elements that should be found in many contemporary websites. For testing I used the HTML5 Outliner.
What confuses me most is the <footer> element, which stubbornly subordinates itself to the main content:
<header>
<img src="[logo-image]">
<h2 class="screen-reader">Name of website</h2>
<nav>
<h2 class="screen-reader">Navigation</h2>
<ul>
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
</ul>
</nav>
</header>
<main>
<header>
<h1>Page title</h1>
</header>
<section>
<h2>Section I</h2>
<section>
<h3>Subsection a</h3>
</section>
</section>
<section>
<h2>Section II</h2>
<section>
<h3>Subsection a</h3>
</section>
</section>
</main>
<footer>
<h3>Footer</h3>
</footer>
The document outline then looks like this:
Name of website
Navigation
Page title
Section I
Subsection a
Section II
Subsection a
Footer
I solved the problem by wrapping the content in <main> with <article> and the content in <footer> with <section>:
<main>
<article>
<header>
<h1>Page title</h1>
</header>
<section>
<h2>Section I</h2>
<section>
<h3>Subsection a</h3>
</section>
</section>
<section>
<h2>Section II</h2>
<section>
<h3>Subsection a</h3>
</section>
</section>
</article>
</main>
<footer>
<section>
<h3>Footer</h3>
</section>
</footer>
The document outline then looks like this, as expected:
Name of website
Navigation
Page title
Section I
Subsection a
Section II
Subsection a
Footer
To get to my question:
Is it necessary to add the elements <article> and <section> to get a clear outline regarding the <footer> element? I think there should be other solutions that make more sense. Because I'm still not sure if the use of <article> is also appropriate for web pages that do not contain articles in the sense of a blog or magazine.
I also wonder if it makes sense to exclude certain sections like <nav> only from the outline algorithm. As far as I understand, a document outline should only encompass the main content of a web page.
The header, footer, and main elements were not categorized as "Sectioning content" and thus have no special effect on the document outline as it was initially intended in HTML5. That's why the HTML5 outliner (as well as the "Structural outline" tool in the Nu HTML Checker, ex-Validator) actually shows "Name of website" and "Page title" in your first example as the same level headings (top level): the scope of the first header is body, and the scope of the last footer is the implied section created by the h1 heading.
However, this can be not as important as it seems because, unfortunately, no browser or assistive technology has implemented the HTML5 document outline algorithm (in any aspect except default styling of h1 headings) and the whole document outline concept is now being largely reconsidered. So the most practical approach is currently to think of header, footer, nav, and main as of native way to express the corresponding ARIA landmark roles rather than something related to heading structure, and build the document outline with heading levels, just like it was before HTML5. The Nu HTML Checker displays this structure as "Heading-level outline".
In the following example html5 page structure, which of the following is more semantic in respect to the sidebar of widgets (elements which appear in the sidebar are elements which appear on multiple pages and do not necessarily, directly, nor particularly relate to this page of content):
<body>
<header id="site-header">
...
</header>
<section id="page-body">
<main>
<header></header>
<article></article>
<footer></footer>
</main>
<aside class="sidebar" id="sidebar-a">
<section id="search-widget">
...search field, etc...
</section>
<section id="recent-articles-widget">
...articles list...
</section>
</aside>
<aside class="sidebar" id="sidebar-b">
<section id="cloud-tag-widget">
...search field, etc...
</section>
<section id="recent-articles-widget">
...articles list...
</section>
</aside>
</section>
<footer id="site-footer"> ... </footer>
</body>
or...
<body>
<header id="site-header">
...
</header>
<section id="page-body">
<main>
<header></header>
<article></article>
<footer></footer>
</main>
<section class="sidebar" id="sidebar-a">
<aside id="search-widget">
...search field, etc...
</aside>
<aside id="recent-articles-widget">
...articles list...
</aside>
</section>
<section class="sidebar" id="sidebar-b">
<aside id="cloud-tag-widget">
...tag list...
</aside>
<aside id="popular-articles-widget">
...articles list...
</aside>
</section>
</section>
<footer id="site-footer"> ... </footer>
</body>
AKA - Is it more semantic or in any way more appropriate to put multiple asides within a section, or include multiple sections within an aside to create a sidebar of widgets? Should they instead be simple divs within a div? Or divs within a section? Divs within an aside? Why?
Which is easier for screen readers or search engines? Why?
The aside is "tangentially related to the content around" it.
Currently, it doesn’t seem to be defined what "around" means exactly. Assuming that it’s (at least) the content of the parent sectioning content element, then this would mean for your examples:
<body> <section> <aside></aside> </section> </body>
The aside is related to the content of the section.
<body> <aside> <section></section> </aside> </body>
The aside is related to the content of the body (i.e., of the whole document).
So in your case, you’ll probably want to have aside as descendant of body (and of no other sectioning content element).
The next thing to decide would be: one aside with several sub-sections vs. several aside. I’d go with a separate aside for each "sidebar block", unless you can logically group (*) these blocks.
* I.e., if there is a natural heading that could be used (it doesn’t matter if you actually use it) to group several sidebar blocks, use one aside with section childs for these.
The <aside> tag defines some content aside from the content it is placed in.
The aside content should be related to the surrounding content.
Is it bad to nave no <header>?
I have this basic structure but I am thinking about wrapping a header arround everything between the body start and the content because the header has also this nice shema.org markup attached. Good Idea?
Just because sometimes the header is not there but the navbars actually contain the brandname and are sort of headers themseves.
if I do this how should I markup whats the <header> right now? A section inside a header is not valid right? Just a normal <div> I guess.
<body>
<div class="nav1"><h1>brandname</h1><nav>...</nav></div>
<header><h1>brandname</h1><p>slogan</p></header> <!-- sometimes this is not there -->
<div class="nav2"><h1>brandname</h1><nav>...</nav></div>
<div>content ...
To this
<body>
<header itemtype="http://schema.org/WPHeader" ...>
<div class="nav1"><h1>brandname</h1><nav>...</nav></div>
<div><h1>brandname</h1><p>slogan</p></div> <!-- sometimes this is not there -->
<div class="nav2"><h1>brandname</h1><nav>...</nav></div>
</header>
<div>content ...
Multiple headers not valid either or? I am thinking of it this way as using the <header> without any CSS styles just for semantic markup. I could think of styling barriers created with this so not 100% satisfied with this.
Or is this valid.
<body>
<header class="nav1"><h1>brandname</h1><nav>...</nav></header>
<header><h1>brandname</h1><p>slogan</p></header> <!-- sometimes this is not there -->
<header class="nav2"><h1>brandname</h1><nav>...</nav></header>
<div>content ...
// just read html5: using header or footer tag twice? this and looks like I stick with the 2nd solution since I not really like the idea of having no header at all
Dont be afraid to answer ;)
Decide for every sectioning root element (e.g., body) and every sectioning content element (e.g., article) if it contains content which is appropriate for header. The spec defines that it’s for "introductory content", and gives the following examples:
introductory or navigational aids
heading (an h1–h6 element) (not required)
table of contents, a search form, or any relevant logos
If there is such content, use a header element. If the content in that sectioning root/content element is scattered, use several header elements.
Keep in mind that the header always applies for "its nearest ancestor sectioning content or sectioning root element":
<body>
<header> <!-- this header is for the whole page --> </header>
<article>
<header> <!-- this header is for the whole article element --> </header>
<div>
<header> <!-- this header is also for the whole article element (and not only for the div element!) --></header>
</div>
<section>
<header> <!-- this header is for this article’s section element only --> </header>
</section>
</article>
<figure>
<header> <!-- this header is for the figure element only --> </header>
</figure>
<strong>
<header> <!-- but this header is also for the whole page (and not for the strong element only!) --> </header>
</strong>
</body>
Let's say, I always want to use the main element in a project for different page types. One of these page types is just a product page, with a header and some sections. Which variant would be semantically correct:
A
<body>
<header>
...
</header>
<main>
<header>
<h1>...</h1>
<img />
</header>
<section>
<h1>...</h1>
<p>...</p>
</section>
<section>
<h1>...</h1>
<p>...</p>
</section>
</main>
<footer>
...
</footer>
</body>
B
<body>
<header>
...
</header>
<main>
<article>
<header>
<h1>...</h1>
<img />
</header>
<section>
<h1>...</h1>
<p>...</p>
</section>
<section>
<h1>...</h1>
<p>...</p>
</section>
</article>
</main>
<footer>
...
</footer>
</body>
I would say A can't be correct. Accordingly to the working draft:
The header element represents introductory content for its nearest ancestor sectioning content or sectioning root element.
The main element is not sectioning content and has no effect on the document outline.
Thus the body > main > header in A would represents the introductory content for body which is the sectioning root element.
For those who might ask, why you don't use B without main. This has technical reasons either I always use main or not. And there are other page types with multiple articles in the main content.
Example A is not correct. I can think of no content where example A would make sense.
You gave the correct explanation why this is the case:
The header belongs to its "nearest ancestor sectioning content or sectioning root element".
In example A, both header elements would belong to body (= nearest sectioning root element), but only the first header should belong to it, while the second header should belong to the product.
As main is not a sectioning content element, you’d need to use one here. article seems to be the correct choice (as all its content is about a product), so example B looks fine.
I need to convert a PSD to HTML5/CSS. I'm having problems finding a definitive answer on what elements to use. My layout consists of a header, content/sidebar and footer. The template structure is below.
I understand you can use multiple header / footer elements with HTML5, I've got the main header/footer tags. The main problem I'm having is with the structure of the content.
I've got a main content area, and then a sidebar, the sidebar content doesn't really relate to the content. Within the sidebar I need to have multiple content boxes.
The content area has various sections, mainly a featured image with text on, and then the rest is just the page text.
From what I understand, using the <section> tag to define the content / sidebar isn't semantic as it's not content related, it's page structure / layout. Does my markup below look correct for the structure I'm trying to achieve?
<header>
</header>
<div class="wrapper">
<div class="main">
<section id="featured-content">
<img />
<p>Featured text</p>
</section>
<section id="main">
<header><h2>Title</h2></header>
<p>The rest of content goes here</p>
</section>
</div>
<aside class="sidebar">
<section class="content-box">
<header>Box title</header>
<p>Box content</p>
</section>
<section class="content-box">
<header>Box title</header>
<p>Box content</p>
</section>
</aside>
</div>
<footer>
</footer>`
In general: If the header only contains a heading, you could omit it.
If the main content of the page could stand on its own (e.g. like a blog post or similar), then you could use article instead of section.
As the #featured-content is some kind of abstract/summary of the main content, it should be part of the article. It makes sense to include it in the header:
<article>
<header>
<h2>(article title)</h2>
<img src="" alt="(article teaser image)">
<p>(article teaser text)</p>
</header>
<p>(article content)</p>
</article>
(Only if the teaser is really complex (e.g. containing headings itself), it could get its own section.)
Using aside for the sidebar is correct, because its content is "tangentially related" to the whole page (!) and not only to the main content (in that case, it should be include in the article, too).
If all content blocks in that aside are somewhat related, using section inside of that aside for each block is correct (but, depending on the actual content, article could be appropriate, also). However, if the blocks inside of that aside have no relation (easy test: do you find a heading for the whole aside?), you could consider using a separate aside for each of it:
<div class="sidebar">
<aside>
<h2>…</h2>
</aside>
<aside>
<h2>…</h2>
</aside>
</div>
So the structure could look like:
<body>
<h1>…</h1> <!-- maybe with header -->
<article>
<h2>…</h2>
</article>
<aside>
<h2>…</h2> <!-- omit it or hide it visually -->
<section> <!-- or article -->
<h3>…</h3>
</section>
<section> <!-- or article -->
<h3>…</h3>
</section>
</aside> <!-- resp. use 1 aside for each block -->
<footer></footer>
</body>