Skip to content
IndexRequest a UIAboutContact

Hamburger to Close Morph

A three-bar menu icon that morphs into an X while the menu is open.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a menu toggle button 44x44px containing three 2px tall, 22px wide bars with 6px spacing, plus a dropdown panel below with three links (Library, Request, About). Clicking the button toggles aria-expanded and an open class. In the open state the top bar translates 8px down and rotates 45deg, the bottom bar translates 8px up and rotates -45deg, and the middle bar fades to opacity 0 and scales to 0 horizontally, all over 260ms cubic-bezier(.3,.8,.2,1). The panel fades from opacity 0 and translateY(-6px) in 180ms and has hidden state removed from tab order. Escape closes the menu and returns focus to the button; clicking outside also closes. The button has aria-controls pointing at the panel and aria-label "Menu". Hover tints the button; focus-visible shows a 2px ring. Under prefers-reduced-motion remove transitions.

About this pattern

Definition

A menu toggle whose three lines rotate and fade into a close cross when the menu opens, and back again when it closes.

Purpose & UX principles

  • One control for both opening and closing keeps the interface simple.
  • The icon change confirms the new state; aria-expanded communicates it to assistive technology.
  • Built from three plain elements, so it needs no icon assets and stays crisp at any size.

Interaction states

  • Closed, open, hover (background tint), focus-visible, pressed.

Motion specification

  • Top and bottom bars move to the centre and rotate 45 degrees, the middle bar fades: 260ms cubic-bezier(.3,.8,.2,1).
  • The panel fades and slides 6px in 180ms.
  • Reduced motion: icon swaps and panel appears instantly.

Responsive behaviour

  • 44px square hit area with a 22px icon.
  • The panel opens below the button and is as wide as its content.

Code

HTML
<div class="wrap">
  <button class="hb" id="hb" aria-label="Menu" aria-expanded="false" aria-controls="pn"><i></i><i></i><i></i></button>
  <nav class="pn" id="pn" hidden><a href="#">Library</a><a href="#">Request</a><a href="#">About</a></nav>
</div>

Related patterns

Top Navigation

↗
Top NavigationNavigation

Drawer

↗
DrawerOverlays & Dialogs

Icon Button

↗
Icon ButtonButtons & Actions