Correcting Web Accessibility Problems in Navigation Menus

The W3C provides detailed instructions for creating accessible menus which we have summarized below along with providing some code examples for improving the accessibility of your menus:

  1. Verify that the menu is marked up using list markup (ul and li).
  2. If a link to the current page is included in the menu, ensure that it includes the aria-current attribute and that CSS is used to visually identify the page as selected.
  3. Ensure links that open a submenu include a visual indication that they open a submenu and aria-expanded attributes.
  4. When activated the triggering links aria-expanded attribute must change to “true”, when deactivate it must change back to “false”.
  5. Ensure submenus do not open when tabbing to a link, if the triggering link is used to open a webpage in addition to opening a submenu a seperate button must be used to trigger the submenu.
  6. Ensure that the “enter” or “space” key can be used to open submenus without triggering a link to open.

Improving the Default WordPress Nav Menu

For many websites making your navigation menu accessible can be accomplished by using the latests Bootstrap Nav Walker.  Complete instructions are provided in the GitHub readme, linked above. If you need help, for a fee one of our accessibility expects can install the latests Bootstrap Nav Walker on your website.

Improving the Elementor Nav Menu Widget

Include the following code in your theme’s scripts file to improve the accessibilty of the Elementor Nav Menu Widget when your menu has only one level of dropdowns.

jQuery(document).ready(function($) {
// improve the accessibility of the elementor main menu
setTimeout(function(){
	jQuery(".sub-menu").attr('role','menu');
	jQuery("a.has-submenu").attr('aria-haspopup','true');
	jQuery(".elementor-nav-menu--dropdown .elementor-sub-item").removeAttr('tabindex');
	}, 500);

	$(document).on("click", "a.has-submenu", function(event) {
		event.preventDefault();
		jQuery(".elementor-nav-menu--dropdown .elementor-sub-item").removeAttr('tabindex');
	});

	$(document).on("keypress", "a.has-submenu", function(event) {
	event.preventDefault();
	var key = event.key;
	if(key === ' '){
	$( this ).trigger( "click" );
	}

	});

// // correct spacebar keypress triggering page slide
    jQuery("body").on("keypress", ".elementor-menu-toggle", function (event) {
        var code = event.key || event.code; //Get keycode.
        if (code != 'Tab' && code != ' ' && code != 'Enter' && code != 'ArrowLeft' && code != 'ArrowUp' && code != 'ArrowRight' && code != 'ArrowDown') //Check each key.
            return; //If it isn't any of those, don't worry about it.

        if ((code == ' ' || code == 'Enter' || code == 'ArrowLeft' || code == 'ArrowRight') && jQuery(':focus').is('input')) //If a space/enter or left/right arrow is pressed in the input, then allow it to happen as normal.
            return;

        event.preventDefault()

    });

	});

Include the following code in your theme’s scripts file to improve the accessibilty of the Elementor Nav Menu Widget when your menu is more 2 or more levels deep.

jQuery(document).ready(function($) {
  // improve the accessibility of the elementor main menu
  setTimeout(function(){
    jQuery(".sub-menu").attr('role','menu');
    jQuery("a.has-submenu").attr('aria-haspopup','true');
    jQuery(".elementor-nav-menu--dropdown .elementor-sub-item").removeAttr('tabindex');
    }, 500);

  $(document).on("click", "a.has-submenu", function(event) {
     event.preventDefault();
    });

      // disable opening on submenu on focus
  $(document).on("focus", "a.has-submenu:not(.elementor-sub-item)", function(event) {

    event.preventDefault();
    if($( this ).attr('aria-expanded') === 'true'){
    $( this ).trigger( "click" );
    }
    });

    // disable subitem links and add expanded notice
    $(document).on("click", "ul.sub-menu>li>a.has-submenu", function(event) {
      event.preventDefault();
       return false;
      });
      $(document).on("focus", "ul.sub-menu>li>a.has-submenu", function(event) {

        event.preventDefault();

       if($(this).find('.expandedNotice' ).length === 0){
        $( this ).append(' <span class="expandedNotice screen-reader-text">expanded menu</span> ');
       }

        if($( this ).attr('aria-expanded') === 'true'){
        }else{
          $('.expandedNotice').detach();
        }
         return false;
        });


    $(document).on("keypress", "a.has-submenu", function(event) {
    event.preventDefault();
    var key = event.key;
    if(key === ' '){
      if($( this ).attr('aria-expanded') === 'false'){
    $( this ).trigger( "click" );
      }
    }

    });

// correct elementor mobile menu not opening on keypress
jQuery("body").on("keypress", ".elementor-menu-toggle", function (event) {
	var code = event.key || event.code; //Get keycode.
	if (code != 'Tab' && code != ' ' && code != 'Enter' && code != 'ArrowLeft' && code != 'ArrowUp' && code != 'ArrowRight' && code != 'ArrowDown') //Check each key.
		return; //If it isn't any of those, don't worry about it.

	if ((code == ' ' || code == 'Enter' || code == 'ArrowLeft' || code == 'ArrowRight') && jQuery(':focus').is('input')) //If a space/enter or left/right arrow is pressed in the input, then allow it to happen as normal.
		return;

	event.preventDefault()

});

});

Generic Menu

The following example code can be used with some modification to make a navigation menu more accessible. If you need assistance, for a fee one of our accessibility expects can customize this code for your particular website.

jQuery(document).ready(function($) {

jQuery(".dropdown-menu").attr('role','menu');
jQuery("a.dropdown-toggle").attr('aria-haspopup','true');
jQuery("a.dropdown-toggle").append(' <span class="caret"></span>');

jQuery("a.dropdown-toggle").on("click keypress", function(event)

{
var thisid = jQuery(this).attr("id");

var key = event.key;

if(key === ' '){
event.preventDefault();
$( this ).trigger( "click" );
}else{

if(jQuery(this).attr('aria-expanded') === 'false') {
jQuery(this).attr('aria-expanded','true');
} else{
jQuery(this).attr('aria-expanded','false');
}

$("a.dropdown-toggle").each(function(){

if(jQuery(this).attr("id") !== thisid ){
jQuery(this).attr('aria-expanded','false');
}
});

}

});

// correct spacebar keypress triggering page slide
jQuery("body").on("keypress", "a.dropdown-toggle", function (event) {
var code = event.key || event.code; //Get keycode.
if (code != 'Tab' && code != ' ' && code != 'Enter' && code != 'ArrowLeft' && code != 'ArrowUp' && code != 'ArrowRight' && code != 'ArrowDown') //Check each key.
    return; //If it isn't any of those, don't worry about it.

if ((code == ' ' || code == 'Enter' || code == 'ArrowLeft' || code == 'ArrowRight') && jQuery(':focus').is('input')) //If a space/enter or left/right arrow is pressed in the input, then allow it to happen as normal.
    return;

event.preventDefault()

});
});

Similar Posts

  • How to Build an Inclusive Company Website

    Image via Pexels A website is a crucial element of any successful company. Your website should introduce potential customers to your business and show them what you have to offer. Unfortunately, many websites are not inclusive and don’t necessarily cater to people with disabilities. If you want to draw in a wider audience and make…

  • |

    Department of Justice (DOJ) Web Accessibility Mandates

    The Department of Justice (DOJ) mandates that state and local government (Title II) websites and mobile apps comply with WCAG 2.1 Level AA standards, with deadlines of April 24, 2026, for populations of 50,000+ and April 26, 2027, for smaller entities. This covers all digital services, including forms, portals, and third-party tools. The rule covers…

  • Web Accessibility Training

    In this web accessibility training course you will learn web and digital accessibility skills for web, documents, and mobile content. This self-paced course cover the most important aspects of Web Accessibility and will teach you how people with disabilities use the web and different types of assistive technologies. Course Length Approximately 8 hours of reading…

  • Common HTML Button Accessibility Problems

    HTML button accessibility is a common problem on websites. Keyboard users routinely use the spacebar and the enter key to activate an html button control. When it doesn’t work, blind users can quickly become disoriented. Luckily this problem can be easily resolved by placing a simple JS script file on your website. It does require…

  • WP Web or WordPress Website Accessibility

    WP Web Accessibility refers to WordPress Website Accessibility. WordPress is an open source content management system. WP Web or WordPress is designed with accessibility in mind but in order for a WordPress website to be truly accessible, website developers must select the right theme and WordPress plugins.  WordPress users and the WordPress community as a…

Accessibility Tools
hide