Skip to content

Morph Menu Icon

A copy-paste morphing shapes component in pure HTML, CSS & vanilla JS. Zero dependencies, framework-agnostic, MIT-licensed.

Morphing ShapesHTMLCSSJavaScriptany framework

Copy into your project

HTML
<!-- Morph Menu Icon — hamburger morphs to X. Vanilla JS toggles .is-open -->
<button type="button" class="nuda-morph-menu" aria-label="Toggle menu" aria-pressed="false">
  <span class="nuda-morph-menu__box" aria-hidden="true">
    <i></i><i></i><i></i>
  </span>
</button>
CSS
/* Morph Menu Icon
   Three bars morph between a hamburger and an X.
   Toggle the .is-open class (see JS tab).
   Customize: --morph-menu-color, --morph-menu-w, --morph-menu-h */

.nuda-morph-menu {
  --morph-menu-color: #e4ff54;
  --morph-menu-w: 32px;
  --morph-menu-h: 24px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 12px;
  outline: none;
}

.nuda-morph-menu__box {
  display: block;
  position: relative;
  width: var(--morph-menu-w);
  height: var(--morph-menu-h);
}

.nuda-morph-menu__box i {
  position: absolute;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--morph-menu-color);
  border-radius: 2px;
  transition: transform 0.4s cubic-bezier(0.4, 0.2, 0.2, 1), opacity 0.2s ease;
  will-change: transform, opacity;
}

.nuda-morph-menu__box i:nth-child(1) { top: 0; }
.nuda-morph-menu__box i:nth-child(2) { top: 50%; transform: translateY(-50%); }
.nuda-morph-menu__box i:nth-child(3) { bottom: 0; }

.nuda-morph-menu.is-open .nuda-morph-menu__box i:nth-child(1) {
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
}
.nuda-morph-menu.is-open .nuda-morph-menu__box i:nth-child(2) {
  opacity: 0;
  transform: translateY(-50%) scaleX(0);
}
.nuda-morph-menu.is-open .nuda-morph-menu__box i:nth-child(3) {
  bottom: auto;
  top: 50%;
  transform: translateY(-50%) rotate(-45deg);
}

.nuda-morph-menu:focus-visible {
  outline: 2px solid var(--morph-menu-color);
  outline-offset: 2px;
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .nuda-morph-menu__box i {
    transition: none;
  }
}
JavaScript
// Toggle the morph between hamburger and X
const btn = document.querySelector(".nuda-morph-menu");
btn.addEventListener("click", () => {
  const open = btn.getAttribute("aria-pressed") === "true";
  btn.setAttribute("aria-pressed", String(!open));
  btn.classList.toggle("is-open", !open);
});

How to use Morph Menu Icon

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More morphing shapes components

← Browse all NudaUI components