Multiple Headers and ARIA Roles - html

I have an HTML Structure which really has 2 headers: At the tippity top of the page it has some navigation items and buttons, below that is another section which holds the logo and what I would call the main navigation.
Both are sectioned off in wrappers because of full width CSS3 gradients so my structure looks something like this:
<div id="topWrap">
<div id="topNavWrap">
<nav id="utilityLinks">
<ul>
<li>Home</li>
<li>Page</li>
<li>Page</li>
<li>Page</li>
<li>Page</li>
</ul>
</nav>
<div id="quickLinks">
<ul>
<li>Login</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
<div id="headerWrap">
<div id="header">
<div id="logo"><img src="logo.png" /></div>
<nav id="mainNav">
<ul>
<li>Main Service Page</li>
<li>Main Service Page</li>
<li>Main Service Page</li>
<li>Main Service Page</li>
<li>Main Service Page</li>
</ul>
</nav>
</div>
</div>
My question is:
In this situation is it acceptable to wrap both of these nav elements in a header element, do I just wrap my main nav and logo in a header element, or do I wrap both in one big header element?
When using Aria, should I use role="main" on my main navigation or my main header element?

Yes, it makes sense to use header for both of these.
As header has no influence on the document outline, it’s up to you use one or several header elements; it doesn’t affect the meaning. If there is no reason not to use one element (i.e., there is no content inbetween that should not be part of header), go with one element.
The ARIA role main is for the main content of a page. Navigation is typically not the main content, unless it’s the only content and purpose of a page. However, in that case you wouldn’t use the header element, as its job is to "exclude" content that is not considered to be part of the main content.

If they are using nav elements you shouldn't simply wrap them in headers. Although you can use multiple header elements in a page, they should represent the top of a 'section', a content area.
A more suitable HTML setup would be:
<header id="topWrap" role="banner">
<div id="topNavWrap">
<nav id="utilityLinks" role="navigation" aria-describedby="utilityLinksH2">
<h2 class="at" id="utilityLinksH2">Site menu</h2>
<ul>
<li>Home</li>
...
</ul>
</nav>
<div id="quickLinks">
<ul>
<li>Login</li>
...
</ul>
</div>
</div>
<div id="headerWrap">
<div id="header">
<div id="logo"><img src="logo.png" /></div>
<nav id="mainNav" aria-describedby="mainNavH2">
<h2 class="at" id="mainNavH2">Service menu</h2>
<ul>
<li>Main Service Page</li>
...
</ul>
</nav>
</div>
</div>
</header>
Notable points are:
wrapping the whole lot in a header, with a role of banner. which should only be used once on a page to denote site furniture at the top of the page. (When used from the body the header applies to the, see the last example in the HTML5 spec.)
Labelling each nav with a hidden sub-heading (use .at to move it offscreen), with aria-describedby.
Main should wrap the main content of the page (that is unique to the page), generally starting just above a H1. There should be only one.

Related

Should I nest a slider inside of <header> tag?

I am currently working on a website, where the site will have a hero slider at the top of the page, under the navigation. Currently, I have written the code like this:
<header>
<h1 class="site-title">Site Title</h1>
<nav id="primary">
<ul class="top-level">
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
</ul>
</nav>
</header>
<section id="hero-banner">
<!-- Banner Content -->
</section>
But I am wondering if it would be appropriate to also include the hero slider inside of the <header> tag? In that case, the code would turn into this:
<header>
<h1 class="site-title">Site Title</h1>
<nav id="primary">
<ul class="top-level">
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
<li class="link">Link</li>
</ul>
</nav>
<section id="hero-banner">
<!-- Banner Content -->
</section>
</header>
Visually, I would consider the hero banner to be grouped with the rest of the <header>, but I'm not sure if reflecting this in the code would be considered semantically correct.
From w3schools:
The element represents a container for introductory content or a set of navigational links.
A element typically contains:
one or more heading elements (<h1> - <h6>)
logo or icon
authorship information
In the end, it's entirely up to you, it's not "bad practice" or "good practice" one way or the other.
It is better to put it outside the <header> tag. As it is not considered as an element of the menu nor the navigation bar. So you are good to go with the first code.

Is the order of the heading, content and footer of a section matter?

Is the order of the heading, content and footer of a section matter ?
for Example,
is this logical ordering :
<article>
<h1>This is the heading</h1>
<content><p>This is the content ...</p></content>
<footer><p>this is the footer</p></footer>
</article>
same for computers comparing to the next illogical ordering :
<article>
<content><p>This is the content ...</p></content>
<footer><p>this is the footer</p></footer>
<h1>This is the heading</h1>
</article>
Semantic markup and accessibility are both important when writing HTML, you have to keep in mind what makes sense to both machines and end users.
Sure, you "could" put elements in any order and style them so they appear to be in a completely different order, but what happens when someone views your website with a screen reader or something similar.
In addition to this the order of your elements is very important when SEO is concerned, the automated search bots that crawl your website don't care what the page "looks" like and have a very structured way in which they identify key areas such as navigation, main content areas, headings and links.
Positioning isn't black and white either, you could have multiple footer elements on one page which would be perfectly fine as long as you have a way to express which footer related to the parent page which is done using an ARIA role.
<body>
<article>
Something
<footer>Something else</footer>
</article>
<footer role="contentinfo">
</footer>
</body>
This will identify the footer with the role as a "navigational landmark", as footers primarily store navigation.
The same goes for a nav element, you could use it for any type of sub-navigation within your website multiple times in whatever order you'd like in addition to using it for your primary navigation as long as you used role="navigation" on the primary nav.
http://www.w3.org/TR/wai-aria/roles
It's very easy to get carried away with using HTML5 elements but as long as you keep them structured semantically within their parent elements and give machines a way to identify key areas of your markup you will be A-OK.
<body>
<header role="banner">
<nav role="navigation">
<ul>
<li>Home</li>
</ul>
</nav>
</header>
<article role="main">
<header>
<h1>Article Heading</h1>
</header>
<aside>
<nav>
<ul>
<li>Article 1a</li>
<li>Article 1b</li>
<li>Article 1c</li>
</ul>
</nav>
</aside>
<p>Yip, dippidy doo.</p>
<section role="complementary">
<h2>Top Articles</h2>
<nav>
<ul>
<li>Article 2</li>
<li>Article 3</li>
<li>Article 4</li>
</ul>
</nav>
</section>
<footer>
<nav>
<ul>
<li>PrevArticle</li>
<li>Next Article</li>
</ul>
</nav>
</footer>
</article>
<footer role="contentinfo">
Copyright
<nav>
<ul>
<li>Home</li>
</ul>
</nav>
</footer>
</body>
In HTML, yes. Element order is significant. (That is not necessarily the case with other SGML/XML derived markup languages).
This is trivial enough to test by looking at the output in a web browser (the standard tool for presenting HTML to the reader) and noticing that the rendered document doesn't make sense.

clicking a link causes logo to move despite same code

It seems that jsfiddle does not let me use multiple html pages so i cannot post both pages. The issue is when i click a link my nav, i notice the logo move a little to the right instead of staying in the same place. the second html page has the exact same html code and css so i don't know why the logo would move once i click a link.
<header>
<div class="header">
<h1 class="logo">New York</h1>
<nav class="main-navigation">
<ul>
<li class="active">Home</li>
<li>Photos</li>
<li>Videos</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>

Can I have a logo image inside a nav element?

In the interest of writing semantic and solid markup, can I position a logo image inside a nav element? Right before the ul element.
<nav>
<img id="logo" />
<ul>
<li>a</li>
<li>b</li>
</ul>
</nav>
Or should I wrap it all in another element like so:
<section id="navigation">
<img id="logo" />
<nav>
<ul>
<li>a</li>
<li>b</li>
</ul>
</nav>
</section>
I would prefer the first one to minimise the markup.
Yes, there's no problem with placing an image within a <nav> tag. Per the MDN and W3C, flow content is permitted content for this tag and among many other elements is the <img> tag.
I'd only insert an image in nav if …
… this image is linked to a page/anchor (for example a link to the front page), or
… this image contains the text "Navigation" or similar (so it should be inserted in a h1)
The spec says:
The nav element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.
So this section shouldn't contain things not about navigation.
Your second example is not what you want, because you would create a wrong outline (because of the outer section).
If it's the main navigation of the page and the image is the site logo, I'd use this markup:
<header>
<h1><img src="logo.png" alt="ACME Inc."></h1>
<nav>
<ul>
<li>a</li>
<li>b</li>
</ul>
</nav>
</header>
If you'd like to link the logo to the home page and the home page is not linked in the ul, I'd insert it in the nav:
<nav>
<ul>
<li><img src="logo.png" alt="ACME Inc."></li>
<li>a</li>
<li>b</li>
</ul>
</nav>
But this is a rare case, because you would still need a page heading and in most cases this would be the logo, and in most cases this should be linked to the home page of the site.

Where to place HTML 5 elements when using SPRY?

I'm building a website using HTML 5 markup, but have hit a problem regarding where to place the the NAV element - because I'm using a SPRY 'Tabbed Panel' for both the navigation and the content:
<header>
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">Home</li>
<li class="TabbedPanelsTab" tabindex="0">Profile/li>
<li class="TabbedPanelsTab" tabindex="0">Contact</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">Content 1</div>
<div class="TabbedPanelsContent">Content 2</div>
<div class="TabbedPanelsContent">Content 3</div>
</div>
</div>
I thought the best place to insert the NAV element would be by wrapping the UL element, but this breaks the SPRY Tabbed panel (maybe I can just fix this by changing some file paths in the CSS?).
Also, seeming as the main content of the site will be held in the 'Content' areas of the tabbed panel, I'm wondering what the best approach is for building this site, with regards to NAV and ARTICLE etc, so that is semantically correct?
Perhaps I am going about this the wrong way?
I'm not familiar with SPRY, but you are probably correct in that you will need to edit the CSS if you wish to have more semantic markup.
Assuming each "tab" is it's own article, here is how I would mark this up:
<div id="TabbedPanels1" class="TabbedPanels">
<nav>
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0">Home</li>
<li class="TabbedPanelsTab" tabindex="0">Profile/li>
<li class="TabbedPanelsTab" tabindex="0">Contact</li>
</ul>
</nav>
<div class="TabbedPanelsContentGroup">
<article class="TabbedPanelsContent">Content 1</article>
<article class="TabbedPanelsContent">Content 2</article>
<article class="TabbedPanelsContent">Content 3</article>
</div>
</div>
It isn't a big change, but it adds at least some better semantics to the markup while still leaving the majority of the structure intact so that there don't need to be MASIVE changes to the SPRY framework code.