FRENVersion française

App navigation

Hamburger menu

Menu hamburger

Demo

Loading demo…

A three-line button that opens the main navigation, hidden by default. It frees up space on small screens, at the cost of navigation that is easier to miss.

Story

Did you know

Norm Cox drew the icon for the Xerox Star in 1981, as a tiny picture of a list. It slept for thirty years before taking off with responsive design and the first iPhone apps.

Timeline

  1. 1981Norm Cox draws the icon for the Xerox Star.
  2. 2009+iPhone apps (Path, Facebook) adopt it for side drawers.
  3. 2012+Responsive design makes it everywhere on the mobile web.
  4. 2014+Backlash: many apps go back to a visible tab bar.

Vocabulary

Names

FR
Menu hamburger, menu burger, menu à trois barres, tiroir de navigation
EN
Hamburger menu, nav drawer, navigation drawer, off-canvas menu, side drawer, hamburger icon

Common uses

  • Main navigation on mobile
  • Secondary menus people rarely open
  • Apps with many sections

Often paired with

The components it usually sits with, by page type, in reading order.

Code

<button id="menu-btn" aria-label="Menu" aria-controls="menu" aria-expanded="false">
  <svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24">
    <path d="M3 6h18M3 12h18M3 18h18" stroke="currentColor" stroke-width="2" />
  </svg>
</button>
<nav id="menu" aria-label="Main" hidden>
  <a href="/">Home</a>
  <a href="/projects">Projects</a>
  <a href="/settings">Settings</a>
</nav>

<script>
  const btn = document.getElementById('menu-btn')
  const menu = document.getElementById('menu')
  function setOpen(open) {
    btn.setAttribute('aria-expanded', open)
    menu.hidden = !open
  }
  btn.addEventListener('click', () => setOpen(menu.hidden))
  document.addEventListener('keydown', (e) => {
    if (e.key !== 'Escape' || menu.hidden) return
    setOpen(false)
    btn.focus()
  })
</script>

Good to know

  • aria-expanded on the button doubles as a CSS hook: [aria-expanded="true"] turns the icon into a cross.
  • Native options: the popover attribute with popovertarget gives you the top layer, Escape and click-outside dismissal with no JS. For a full-screen drawer, use <dialog> + showModal().
  • A scrolling drawer scrolls the page behind it once it hits the end: put overscroll-behavior: contain on the drawer.
  • On desktop, testing shows visible navigation gets used more than navigation hidden behind the icon.

Accessibility

Must have

  • A real <button> with an aria-label: the icon alone has no accessible name (WCAG 4.1.2).
  • The button exposes its state with aria-expanded and points to the menu with aria-controls.
  • Escape closes the menu and sends focus back to the button.

Often forgotten

  • A drawer moved off-screen with transform is still reachable with Tab. Add hidden, inert or visibility: hidden when it is closed.
  • Keep the label fixed ("Menu"): aria-expanded already announces open or closed. Changing the label as well says it twice.
  • A target of at least 24 × 24 px (WCAG 2.5.8), 44 × 44 px to do it properly.

Nice to have

  • Write "Menu" next to the icon: not everyone recognises the three lines.
  • If the drawer covers the page, a modal <dialog> keeps focus inside and makes the rest inert.

Who uses it