Hey this is almost there. Great job. There is one issue that absolutely needs to be fixed, but hopefully it won’t take you too long to do.
I know it seems like the aria-expanded
attribute should go on the list, since that is what is being expanded, but it actually goes on the button
. So you’ll need to change that for all three buttons in your menu. Each button should start with aria-expanded="false"
, and then toggle to aria-expanded="true"
when you click on it to expand the menu, and then back to aria-expanded="false"
when you click on the button again to close the menu.
There are also a few minor issues that should be fixed as well. One is the use of aria-label
. You only need to use aria-label
if there isn’t text already available to give the element a name. For the submenu buttons, you have actual text inside the button
so you don’t need aria-label
on those buttons. And since every link in the menu has text then you don’t need aria-label
on those. Basically, you can get rid of the aria-label
s on the submenu buttons and all links in your menu because they are all doing unnecessary work. This is a best practice and basic rule of ARIA: only use ARIA attributes when absolutely necessary.
As a side note, most of your aria-label
s are basically the same as the actual text in the element except you have added “link to …” or “opens the … submenu”. This is not needed. Screen reader users already know that something is a link or something is a button that opens something. You don’t need to include this extra “helper” text because it just causes unnecessary words to be read to them which is tedious and possibly confusing.
Another issue that should be fixed is the alt text on the icons in the Features submenu. Those would be considered “decorative” text and thus should have empty alt text (i.e alt=""
). That way screen readers will ignore them and just announce the actual text for the link. Another way to hide these decorative images from screen readers is to add aria-hidden="true"
to them. You have done this for the up/down arrows on the submenu buttons (which is great). I would just add that generally, if you are using aria-hidden="true"
to hide an image then you don’t need alt text for it, so you could use alt=""
on the image.
For the hamburger button, you have hidden the images with aria-hidden="true"
(again, this is perfectly fine, and you could set the alt text to alt=""
) but in this case you don’t have any actual text inside the button so you do need to use aria-label
to give it a name (which you have done). Naming elements with aria-label
is a skill in itself. Generally, you want it to be as short as possible and just describe the element. Since this button controls the main navigation menu, then you would want aria-label
to be something like “main menu” or even just “menu”. You don’t need to add information like “Open/close” and “in mobile” to the aria-label
. Screen reader users will already know about the open/close functionality of the button because you will have the aria-expanded
attribute on it. That’s the purpose of the aria-expanded
attribute, to tell screen reader users that the button controls something that can be hidden or expanded. So the aria-expanded
attribute is doing this work for you (that’s why it is required to be on the button). And the “in mobile” text at the end is unnecessary because it isn’t important information that screen reader users need to know, so it just adds extra words they have to listen to.
The placement of the hamburger button should also be fixed. It should be the first element inside of the nav
element. The nav
element acts as a landmark. Screen reader users can use landmarks to navigate the page. Main page menus are generally placed inside the nav
landmark at the top of the page. So if they navigate to the nav
landmark then they are going to assume that everything for the menu is inside the nav
landmark. And since the hamburger button is part of the menu, it should be inside the nav
landmark.
As a side note, you don’t need to add “navigation” to the end of the aria-label
for the nav
element. Screen reader users will already know that it is for navigation because it is the nav
element and it will automatically be treated as the navigation landmark by their screen reader and they will hear that it is for “navigation”.
I know this seems like a lot and I can understand your frustrations with accessibility. I can tell that you were trying your best to be accessible, which I applaud. Please don’t stop trying. I think that perhaps you just got some misleading information up front and it lead you to overcomplicate things a little. Notice that most of the changes I recommended above were about removing unnecessary things you added. I’m not going to lie, some accessibility issues are extremely complicated and take a lot of work and testing to implement correctly. But those are much more uncommon, and you certainly don’t have anything like that on your page.
Keep up the good work!