Sub topic 3
Click, Hover, and Escape Behavior in Mega Menus
Assume you know basic HTML and CSS, links and lists, JavaScript event handling, and responsive design. A mega menu is a large submenu that groups many related links. Its interaction must work with a mouse, keyboard, and touch input.
Click, hover, and Escape behavior
Use a button to open a mega menu. Keep its aria-expanded value synchronized with the panel. Click is the most reliable activation method because hover does not exist on touch screens.
const button = document.querySelector('[aria-controls="products-panel"]');
const panel = document.getElementById("products-panel");
function setOpen(open) {
button.setAttribute("aria-expanded", String(open));
panel.hidden = !open;
}
button.addEventListener("click", () => {
setOpen(button.getAttribute("aria-expanded") !== "true");
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape" && button.getAttribute("aria-expanded") === "true") {
setOpen(false);
button.focus();
}
});Hover may open a menu on desktop, but do not make hover the only method. Add a small delay before closing so the pointer can move into the panel.
Mega menu accessibility pitfalls
Every menu needs a visible focus style. Group links under headings, use meaningful link text, and provide an accessible name for each nav landmark. Do not place unrelated content in the panel. Ensure the panel remains usable when text is enlarged and when controls are reached with the Tab key.
What a footer is for
A footer provides secondary navigation and supporting information. It commonly contains contact links, company information, legal policies, social links, and copyright text. It should not repeat every primary-navigation link.
Organizing and marking up footer content
Group related links under short headings. Use a separately labeled nav so screen-reader users can distinguish footer navigation from primary navigation.
<footer>
<nav aria-label="Footer">
<section>
<h2>Company</h2>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</section>
<section>
<h2>Legal</h2>
<ul>
<li><a href="/privacy">Privacy policy</a></li>
<li><a href="/terms">Terms of use</a></li>
</ul>
</section>
</nav>
<p><small>© 2026 Example Co.</small></p>
</footer>On small screens, stack groups vertically and keep links easy to tap. Use CSS grid or flexbox rather than fixed-width columns.
Testing navigation and footers
Test with Tab and Shift+Tab. Confirm that focus is visible, Escape closes the menu, and focus returns to its button. Test at narrow widths, with touch, zoom, and a screen reader. Check that labels identify each landmark and that every link has a clear destination.
Exercise
Why should Escape return focus to the mega menu button?
Show answer
It gives keyboard users a predictable position after the panel closes, so they do not lose their place in the page.