Course contentsShow
← Web Development
Lesson 1166 of 2,98221. Accessible ComponentsFree lesson

Keyboard Navigation in Menus

Implementing arrow key navigation, Home/End, and type-ahead search within dropdown menus.

Keyboard Navigation in Menus

You'll learn: How to implement arrow key navigation, Home/End keys, and type-ahead search within dropdown menus for full keyboard accessibility.

Why Navigation Patterns Matter

Once you've built a menu with proper semantics (using menu and menuitem roles), users expect it to behave like native desktop menus. That means arrow keys should move between items, Home/End should jump to the first/last item, and typing should quickly find matching items—just like the File menu in your favorite application.

Core Navigation Features

Arrow Key Navigation

In vertical menus (the most common pattern), Up Arrow moves focus to the previous item and Down Arrow moves to the next. When you reach the end, focus typically wraps around to the beginning, creating a circular navigation pattern.

menu.addEventListener('keydown', (e) => {
  if (e.key === 'ArrowDown') {
    e.preventDefault();
    moveFocusToNext();
  } else if (e.key === 'ArrowUp') {
    e.preventDefault();
    moveFocusToPrevious();
  }
});

Home and End Keys

Home jumps directly to the first menu item, and End jumps to the last—perfect for quickly navigating long menus without repeatedly pressing arrows.

Type-Ahead Search

When users type a letter, focus should jump to the first menu item starting with that character. Typing multiple letters quickly should narrow the search further (e.g., typing "sa" finds "Save As" before "Settings").

Key Takeaway: Keyboard navigation in menus requires implementing arrow keys for sequential movement, Home/End for boundary jumps, and type-ahead search for quick access—creating an experience that matches users' expectations from desktop applications.