Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In HTML5, can you nest NAV elements?

I have a site-wide main menu, which I'm currently using <nav> for. I also have a submenu, which is right under the main nav and is different for every product on the site. What's the best practice to handle this?

Currently, I have a separate <div id="secondary-nav"> below the main nav. But since they're both within the <header> of the page, I was thinking about having a nested <nav> instead. Is this an OK practice in HTML5?

like image 771
Joe Avatar asked Aug 08 '11 18:08

Joe


People also ask

Can you have multiple NAV elements HTML?

Yes, absolutely. You can have multiple header , nav , and footer tags sans penalty.

Is Nav an HTML5 element?

The <nav> tag is one of the HTML5 elements. It is used to specify a block of navigation links, either within the current document or to other documents. Examples of navigation blocks are tables of contents, menus, and indexes.

Why is it important to use HTML5 navigational content?

The purpose of this technique is to help users of assistive technology, such as screen readers, to quickly and easility navigate to a section of a page, and to skip over sections of a page that they do not need.

Can NAV be inside header?

It is important to note that <nav> can be used inside of the <header> element but can also be used on its own. By using <nav> as a way to label our navigation links, it will be easier for not only us, but also for web browsers and screen readers to read the code.


2 Answers

It's perfectly acceptable to use nav there. You may also want to look at aside if it can be removed, or look to use section tags within the nav to better divide up the content. This returns to the whole semantics debate, where my stance is, if it makes sense, do it. It doesn't need to be 100% semantically correct, as no one outside of the people who look at source code will ever know.

like image 160
ayyp Avatar answered Sep 22 '22 12:09

ayyp


There is currently nothing in the specs that indicates that nesting navs is not allowed. And seeing as <nav> is a block-level element, there is nothing wrong with nesting them.

like image 32
Madara's Ghost Avatar answered Sep 23 '22 12:09

Madara's Ghost