Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I can't use role="navigation" attribute in html nav tag?

My code-snippet is below:-

<nav role="navigation" data-offset-top="100" data-spy="affix" class="navbar navbar-inverse navbar-fixed-top">

When I validate this code, it will give me a warning, but the same code is available on bootstrap documentation.
Here is a screenshot - bootstrap navbar code

like image 890
Waseem Barcha Avatar asked May 13 '16 17:05

Waseem Barcha


People also ask

Does nav element need role navigation?

The navigation landmark role is used to identify major groups of links used for navigating through a website or page content.

What is role in NAV HTML?

The navigation role is a landmark role. Landmark roles provide a way to identify the organization and structure of a web page. By classifying and labeling sections of a page, structural information conveyed visually through layout is represented programmatically.

Which tag is used to allow navigation 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.

How do you write navigation in HTML?

The <nav> tag is used for declaring the navigational section in HTML documents. Websites typically have sections dedicated to navigational links, which enables users to navigate the site.


2 Answers

<nav role="navigation"> is redundant, so it's discouraged. During transitional periods for some elements it's encouraged to use both the [role] attribute in addition to the new tag, but only until browsers support the implicit semantics for the new tag.

This is more commonly seen with <main role="main"> which was a later addition to HTML.


In the end, the w3c validator doesn't say you can't use the redundant markup, it just warns you that it's superfluous and unnecessary.

For example, validating:

<!doctype html>
<title>example</title>
<nav role="navigation"></nav>

Produces the following warning:

Warning: Element nav does not need a role attribute.

If it were invalid markup, you'd receive an error.

like image 106
zzzzBov Avatar answered Sep 28 '22 08:09

zzzzBov


Because role="navigation" is optional and it is only for user agents that supports ARIA.

In this example, the page includes a top navigation section that does not use the ARIA role of navigation, and a navigation at the bottom of the page that does. The role of navigation is recommended as of September 2014, but at some future point in time may not be needed.

Example: https://awkawk.github.io/using_nav.html

like image 43
RobertoB Avatar answered Sep 28 '22 09:09

RobertoB