Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 nav element vs. role="navigation"

Do all of the following carry the same semantic meaning? If not please explain your answer.


1.

<nav>     <ul>         <li><a href="#">link</li>         <li><a href="#">link</li>         <li><a href="#">link</li>         <li><a href="#">link</li>     </ul> </nav> 


2.

<div role="navigation">     <ul>         <li><a href="#">link</li>         <li><a href="#">link</li>         <li><a href="#">link</li>         <li><a href="#">link</li>     </ul> </div> 


3.

<ul role="navigation">  <! -- breaks HTML5 specification 3.2.7.4 Implicit ARIA Semantics       navigation is not an allowed value of role on ul -->     <li><a href="#">link</li>     <li><a href="#">link</li>     <li><a href="#">link</li>     <li><a href="#">link</li> </ul> 
like image 269
Web_Designer Avatar asked Jan 06 '13 09:01

Web_Designer


People also ask

What is the importance of NAV element in HTML5?

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.

What is the purpose of a nav element?

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. Not all groups of links on a page need to be in a nav element — the element is primarily intended for sections that consist of major navigation blocks.

What is the HTML 5 element for the navigation bar?

<nav>: The Navigation Section element The <nav> HTML element represents a section of a page whose purpose is to provide navigation links, either within the current document or to other documents.

Should the nav element be used for major navigation blocks?

The <nav> element is intended only for major block of navigation links. Browsers, such as screen readers for disabled users, can use this element to determine whether to omit the initial rendering of this content.

What is the use of <nav> element in HTML?

The <nav> element is one of them, which will help users find the navigation sections of a page. The <nav> element allow the author to mark up major navigation blocks in the HTML5 pages.

How to use navigation elements in HTML5 pages?

HTML5 has a variety of section elements that can aid in this. The <nav> element is one of them, which will help users find the navigation sections of a page. The <nav> element allow the author to mark up major navigation blocks in the HTML5 pages.

What is the purpose of Navigation section in HTML?

<nav>: The Navigation Section element The <nav> HTML element represents a section of a page whose purpose is to provide navigation links, either within the current document or to other documents. Common examples of navigation sections are menus, tables of contents, and indexes.

What is the <nav> tag used for?

The <nav> tag defines a set of navigation links. Notice that NOT all links of a document should be inside a <nav> element. The <nav> element is intended only for major block of navigation links. Browsers, such as screen readers for disabled users, can use this element to determine whether to omit the initial rendering of this content.


2 Answers

As Alohci noted, according to HTML5, example 3 is not allowed.

But example 1 and 2 are not semantically equivalent.

nav is a sectioning element, div not. So example 1 creates an untitled section (similar to an empty heading), changing the whole document outline.

Also nav always belongs to its parent sectioning content (resp. sectioning root), so you can have a navigation for the whole site, a navigation for the main content, a navigation only for chapter 3 of the main content, and/or a navigation for secondary content in the sidebar etc.

This difference is represented in the definitions of the navigation role

A collection of navigational elements (usually links) for navigating the document or related documents.

and the nav element (bolded by me):

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.


Also note: a HTML5 user-agent that doesn't support/know WAI-ARIA wouldn't understand that example 2 contains navigation (and vice-versa).

like image 111
unor Avatar answered Sep 20 '22 11:09

unor


Twitter Bootstrap uses <nav role="navigation">

This seems like it covers all needs most effectively.

Be sure to add a role="navigation" to every navbar to help with accessibility.

It's also advised by w3.org

like image 24
bdanin Avatar answered Sep 18 '22 11:09

bdanin