AI CSS Animations

Guides · · Maxwell Prehoda

10 Hamburger Menu Animation Examples, From Apple's Two-Line Morph to Full Libraries

A hamburger animation does one job: show that the button opened something and is now the way to close it. The best ones morph the three (or two) lines into an X or an arrow in about a quarter of a second, in two steps: the lines come together, then they turn. Anything slower makes a menu feel heavy, and anything without a clear closed state leaves people hunting for the exit.

Below are the implementations worth copying, starting with the exact timing Apple uses on apple.com, then the libraries most people install (Jonathan Suh's Hamburgers, hamburger-react, useAnimations), Android's built-in morph, and the two references that decide whether your menu works at all: Inclusive Components on accessibility and Nielsen Norman Group's data on hidden navigation. Our own pure-CSS menus play live where they fit.

1. Apple.com's two-line menu morph: Best for a refined, minimal menu icon on a marketing site

Platform: Inline SVG with SMIL animate (apple.com)

Live from our directory: Hamburger Menu to X Hover. Copy the HTML and CSS →

On a phone-sized screen, apple.com's global navigation uses a hamburger with only two lines. Read the page source and the morph is two SVG polylines with SMIL animate elements: over 0.24 seconds, both lines first slide to the middle (an ease-in curve, 0.42, 0, 1, 1) and then rotate into an X (an ease-out curve, 0, 0, 0.58, 1). Closing plays the same path in reverse.

That two-step choreography (collapse, then rotate) is the detail that makes it feel precise rather than floppy. The button also carries an accessible label for each state (Menu and Close), so screen readers can hear the change, and it points at the list it controls with aria-controls.

Our Hamburger Menu to X below is a pure-CSS version of the same two-step idea with three bars: they slide together, the middle one shrinks away, then the outer two cross, with the translate and rotate transitions run in sequence and reversed on the way back.

Watch out for: Two lines read less obviously as a menu than three for some audiences, and Apple can rely on brand familiarity. If your users are less tech-savvy, keep three lines or add the word Menu.

2. Hamburgers by Jonathan Suh: Best for picking from many CSS morphs with no JavaScript library

Platform: CSS and Sass, MIT

The library most people mean when they say "animated hamburger". Jonathan Suh's Hamburgers has around 7,000 GitHub stars and offers 17 named types, including 3DX, Arrow, Collapse, Elastic, Emphatic, Slider, Spin, Spring, Squeeze, Stand and Vortex, most with a reverse version for 31 classes in all.

You add the base markup plus a type class such as `hamburger--collapse`, then toggle `is-active` with a line of JavaScript. The Sass version lets you set padding, line width and color, and drop the types you don't use so you only ship one.

The demo page is the fastest way to feel the difference between a spin, a squeeze and a collapse before you commit.

Watch out for: The repository hasn't seen a push since 2023, so treat it as finished rather than maintained. Import only the type you use; the full CSS includes all 31 variants.

GitHub ↗

3. hamburger-react: Best for React apps that want a tiny, tunable burger

Platform: React, about 1.5 KB min and gzip

A React component with 14 variants: Tilt (the default), Squash, Cross, Twirl, Fade, Slant, Spiral, Divide, Turn, Pivot, Sling, Squeeze, Spin and Rotate. Using one adds about 1.5 KB to your bundle.

Its props are a short course in tuning menu motion. `duration` defaults to 0.4 seconds (set 0 to turn animation off), `easing` defaults to cubic-bezier(0, 0, 0, 1), a very strong ease-out, and `rounded`, `direction`, `size` and `distance` adjust the look. It also pads the icon to a tap target of at least 48 by 48 pixels and takes a `label` for screen readers.

Watch out for: 0.4 seconds is on the slow side for a control people tap often. Try 0.25 to 0.3 seconds, and wire `duration` to 0 when the user prefers reduced motion.

4. Android's DrawerArrowDrawable: Best for native Android apps with a navigation drawer

Platform: AndroidX AppCompat

Android ships the hamburger-to-arrow morph as a system drawable. The docs describe it as a drawable that can draw a "Drawer hamburger" menu or an arrow and animate between them, with the progress between the two states controlled by `setProgress`. `setSpinEnabled` decides whether the bars rotate during the transition.

Because progress is a number, you can tie it to the drawer's slide position, so the icon morphs exactly as far as the drawer is open. That direct link between gesture and icon is better than any fixed-duration animation, and it is worth copying on the web when a menu can be dragged.

Watch out for: An arrow means "back", not "close". Use the arrow morph when the menu is a level of navigation the user returns from, and an X when it is an overlay they dismiss.

5. useAnimations menu icons: Best for Lottie-based menu icons with click toggles

Platform: Lottie JSON and React, MIT

useAnimations is a free set of about 300 micro animations as Lottie files, with a React package and shadcn/ui registry items. It includes four menu toggles (Burger Menu and Menu V2, V3 and V4), each built to play forward on open and back on close.

It is a good fit if your product already uses Lottie for icons, because the menu then matches the rest of your animated icon set. Static SVGs of each state are included too, for places where you don't want the player.

Watch out for: Loading a Lottie player for a single menu icon is heavy compared with a few lines of CSS. Use it only if Lottie is already on the page.

6. Inclusive Components: menus and menu buttons: Best for getting the toggle's accessibility right

Platform: Article by Heydon Pickering (HTML and ARIA)

The animation is the easy part. Heydon Pickering's chapter on menu buttons covers what the morph is standing in for: a real button whose `aria-expanded` changes on click to say whether the menu is open, and a navigation disclosure rather than an ARIA menu. He argues that `role="menu"` is for application behavior, not navigation links, so a site menu should stay a list of links revealed by a button.

He also recommends keeping the button inside the nav element and placing the list right after it in focus order, because aria-controls is only supported in the JAWS screen reader. Get this right first, then animate the icon to mirror the aria-expanded state.

Watch out for: A pure CSS checkbox hack can animate a hamburger with no script, but it doesn't expose expanded state properly to assistive technology. Use a button with aria-expanded for production menus.

7. Nielsen Norman Group on hidden navigation: Best for deciding whether to hide your menu at all

Platform: UX research (NN/g, 2016)

Before you polish a hamburger, check whether you need one. In Kara Pernice and Raluca Budiu's study, desktop users used hidden navigation in 27% of cases versus 48% for visible navigation, and tasks took at least 39% longer. On mobile the gap was smaller, but hidden navigation still cut discoverability by more than 20% compared with visible or combined navigation.

Their recommendation: avoid hidden navigation on desktop, and on mobile show links openly if you have four or fewer. A beautiful morph doesn't fix a menu nobody opens.

Watch out for: The study is from 2016, and people are more familiar with the icon now. The direction of the finding still holds: visible links get used more than hidden ones.

8. Our Floating Action Button Menu: Best for mobile apps with a few primary actions

Platform: Motions directory, free, pure CSS Ours

Live from our directory: Floating Action Button Menu. Copy the HTML and CSS →

Not every menu is navigation. A round plus button that turns into a close X and fans three mini action buttons out in an arc, one after another, is the right pattern for "create" menus: new note, new photo, new task.

Each action rides a rotate, translate, rotate-back chain so its icon stays upright as it swings out. The plus-to-X turn is the same closed-to-open signal as a hamburger, in a shape that suits actions.

Watch out for: Keep it to three to five actions with labels, and close it when one is chosen or the user taps outside.

9. Our Glass Sidebar: Best for dashboards that collapse navigation to an icon rail

Platform: Motions directory, free, pure CSS Ours

Live from our directory: Glass Sidebar. Copy the HTML and CSS →

On desktop, the better alternative to a hamburger is often a collapsed rail. This frosted icon rail slides open into a full sidebar on hover, blurring the dashboard it covers. Labels fade in only after the width settles, and the active item keeps an accent marker.

Delaying the labels until the panel has finished growing is the trick: text that appears while its container is still moving looks squashed. The same rule applies to any menu that slides in.

Watch out for: Hover-to-open needs a keyboard and touch equivalent. Add a toggle button with aria-expanded for people who can't hover.

10. Our Staggered Dropdown Menu: Best for the menu panel that opens after the icon morphs

Platform: Motions directory, free, pure CSS Ours

Live from our directory: Dropdown Menu on Hover. Copy the HTML and CSS →

The icon is only half the animation; the menu that opens is the other half. This dropdown unfolds under its trigger on hover or keyboard focus, with each item dropping in a beat after the last, and an invisible hover bridge keeps the panel clickable as the pointer moves into it.

Pair a 250ms icon morph with a short stagger like this (a few tens of milliseconds per item) and the open feels like one gesture. Browse the Menu Hover Effects collection for the link styles inside the panel.

Watch out for: Cap the stagger. With twelve items, a per-item delay adds up to a menu that is still arriving when the user wants to click; stagger the first five or six and show the rest together.

How to choose a hamburger menu animation

Match the end shape to the meaning

Morph to an X when the menu is an overlay you close (most websites, like apple.com). Morph to an arrow when the menu is a level you go back from, as Android's DrawerArrowDrawable does. Morph a plus to an X for action menus like our Floating Action Button Menu. A spinning, elastic or 3D flip is decoration on top of that choice, not a replacement for it.

Match the timing to the tap

Menus are tapped often, so aim for about 200 to 300ms, like Apple's 0.24 seconds, with two steps (collapse, then rotate) and a strong ease-out at the end. Libraries default slower (hamburger-react uses 0.4 seconds), so tune them down. Under prefers-reduced-motion, swap icons instantly.

Match it to your stack, then fix the semantics

No framework: copy a CSS morph from our Hover Effects directory or Jonathan Suh's library. React: hamburger-react. Lottie already on the page: useAnimations. Native Android: DrawerArrowDrawable. Whatever you pick, follow Inclusive Components: a real button, aria-expanded, a label, and the list right after it in the nav.

Ship a better menu toggle today

Open your site on a phone and tap the menu ten times. If you notice the animation by the third tap, it is too slow. If you can't tell whether the menu is open from the icon alone, the end state isn't clear. Fix those two things and most hamburgers are done.

If you want a morph that matches your brand's icon style, describe it in the creator (or paste your header's HTML) and get production-ready CSS with a reduced-motion version built in.

A prompt to start from
Animate my hamburger menu button (HTML below) with CSS only.
Three 2px bars, 24px wide. When the button has aria-expanded="true":
first 120ms, the top and bottom bars move to the middle and the middle bar fades (ease-in),
next 120ms, the two bars rotate to 45 and -45 degrees into an X (ease-out).
Reverse the same steps on close.
With prefers-reduced-motion, switch between the two icons instantly.
Keep a 44px tap target and do not change the button's size.

Make your own with AI →

Common questions

How do you animate a hamburger menu into an X with CSS?

Make three bars (spans or pseudo-elements). On the open state, translate the top and bottom bars to the center and fade the middle one, then rotate the two remaining bars to 45 and -45 degrees. Run the translate first and the rotate second using transition delays, and reverse the order on close. Our Hamburger Menu to X shows the sequence.

How long should a hamburger menu animation take?

Around 200 to 300ms. Apple's menu icon on apple.com morphs in 0.24 seconds. Menus are opened often, so anything much longer starts to feel sluggish.

Are hamburger menus bad for UX?

On desktop they often are: Nielsen Norman Group found hidden navigation was used far less than visible navigation and slowed tasks. On mobile they are a reasonable tradeoff when you have more than about four top-level links. Show links directly when you have room.

Should a hamburger menu use role="menu"?

Not for site navigation. Heydon Pickering's Inclusive Components recommends a disclosure: a button with aria-expanded that shows and hides a list of links. ARIA menus are meant for application-style commands.

What is the best hamburger menu animation library?

For plain CSS, Jonathan Suh's Hamburgers (17 types, MIT). For React, hamburger-react (14 variants, about 1.5 KB). For Lottie icon sets, useAnimations. For one icon, a few lines of your own CSS are usually lighter than any library.

Sources