Monday, 5 August, 2019 UTC


Summary

In this lesson, we are going to use the :focus-within pseudo class as a CSS only way improve the accessibility of a navigation menu. If I were to use :focus on the `
  • `, it wouldn't work because the list items have a tabindex of -1. [:focus-within](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-within) represents an element that has received focus or contains an element that has received focus. So when it's child, the anchor, receives focus, we can use the same thing that we do on the hover effect. Be wary of browser support though! If you have to support IE and Edge check out my other lessons: [Expand a Menu on a Focus Event to Improve Accessibility](https://egghead.io/lessons/javascript-expand-a-menu-on-a-focus-event-to-improve-navigation-accessibility) and [Collapse a Submenu on the Blur Event to Improve accessibility](https://egghead.io/lessons/javascript-collapse-a-submenu-on-the-blur-event-to-improve-navigation-accessibility)