Hambuger menu

From thedaviddias/ux-patterns-for-developers · View interactive version

Hambuger menu is an AI agent skill from the GitHub repository thedaviddias/ux-patterns-for-developers. Use when you need to display a menu icon for mobile devices.

How to use this skill

Skill file

Hamburger Menu

Display a menu icon for mobile devices

What it solves

Hamburger Menu is a three-line icon (☰) that toggles a hidden navigation panel, primarily on mobile and small-screen devices. Tapping or clicking the icon reveals the site's navigation, then hides it again when dismissed.

This pattern conserves screen real estate on smaller viewports while keeping the full navigation accessible behind a single, universally recognized affordance.

When to use

Use Hamburger Menu to provide full navigation access on small screens without consuming permanent layout space.

Common scenarios include:

When to avoid

Implementation workflow

  1. Confirm the pattern matches the problem and constraints before copying the example.
  2. Start from the anatomy and examples in references/pattern.md, then choose the smallest viable variation.
  3. Apply accessibility, performance, and interaction guardrails before layering visual polish.
  4. Use the testing guidance to verify behavior across keyboard, screen reader, responsive, and failure scenarios.

Accessibility guardrails

Do's ✅

Don'ts ❌

Performance guardrails

Target Metrics

Optimization Strategies

CSS-Only Toggle (Progressive Enhancement)

/* Use :has() or checkbox hack for no-JS base */
.nav-panel { transform: translateX(-100%); }
.hamburger-toggle[aria-expanded="true"] ~ .nav-panel {
  transform: translateX(0);
}

Common mistakes

Using Hamburger on Desktop

The Problem:

Hiding navigation behind a hamburger icon on large screens reduces discoverability and forces unnecessary clicks.

How to Fix It:

Only use the hamburger pattern below a responsive breakpoint (typically 768px or 1024px). Show full navigation on desktop.

Missing Focus Management

The Problem:

When the menu opens, focus stays on the toggle or moves to the page body, leaving keyboard users stranded.

How to Fix It:

Move focus to the first focusable element inside the panel on open. Trap focus within the panel. Return focus to the toggle on close.

No Escape Key Support

The Problem:

Keyboard users have no way to quickly dismiss the menu without tabbing to a close button.

How to Fix It:

Listen for the Escape key and close the menu, restoring focus to the toggle button.

Related patterns


For full implementation detail, examples, and testing notes, see references/pattern.md.

Pattern page: https://uxpatterns.dev/patterns/navigation/hambuger-menu

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.