Skip to content
animorio
IT
Back to the library

Morphing icons

SVG, HoverGSAPMediumCompressed weight: Demo 5.1 KBGSAP 28 KBFreeDownload the zip

Six square keys on a very light grey, each with a line-drawn icon: when pressed, the icon’s strokes bend and move until they become its pair (menu becomes close, play becomes pause, moon becomes sun), on a short spring with a breath of bounce, while the key sinks and the state name below rewrites itself letter by letter.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Morphing icons" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Icons that morph into each other</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- six icon keys: each icon is drawn with the same ten strokes, so pressing a key bends and moves the strokes of one
         icon into the other (menu into close, play into pause, moon into sun) instead of swapping two pictures -->
    <section class="board" data-board aria-label="Icon toggles">
      <div class="grid" data-grid></div>
      <p class="hint">Tap a key to switch its icon</p>
    </section>
    <svg class="pointer" data-pointer viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.5 18.5 12 12.2 13.4 9.4 19.6Z"></path></svg>
  </main>

  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

12 values to change

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Morphing icons” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On a very light grey there are six white square keys with wide corners, in two rows of three, each with the name of its state in grey below: Menu, Play, Add, Download, Notify, Dark. Inside each key is an icon drawn with ten thin strokes. When pressed, the key sinks by a hair, its shadow tightens, and it comes back up on a spring that goes a hair past its place. Meanwhile the icon’s strokes bend and move until they draw its pair: the three menu lines turn and become a cross while the middle one vanishes, the play triangle opens into the two pause bars, the plus turns and stretches into a minus, the falling arrow loses its shaft and becomes a check, the bell shakes and gets a slash, the moon turns a quarter and swells into a sun with rays coming out of its edge. Halfway through the strokes get slightly bolder, then thin again. The switched-on icon turns purple. Below, the old name leaves upwards letter by letter and the new one rises from below. On hover the icon grows a breath. A drawn pointer presses the six keys one after the other, then again, and everything goes back to how it was.

How it works

Ten strokes per icon

Every icon is made of ten strokes, and every stroke is a single Bézier curve: a start point, two control points, an end point and an opacity. Straight lines are curves with their controls at one and two thirds. A stroke an icon does not use is folded into a point with zero opacity, right where it will be born in the other icon: that is how the sun’s rays come out of the moon’s edge.

One number for the change

The change is a number p going from 0 to 1 (or 1 to 0) with GSAP and a back.out curve: every frame all the numbers of the ten strokes are mixed between the two icons by p and the d attribute is rewritten. With back.out p goes a little past 1 and comes back, so the strokes really bounce instead of fading.

Rotation and thickness

Each pair has its own rotation (the menu turns 180 degrees, the moon minus 90) that grows with p. The stroke width rises by 22 percent halfway through with a sine on the progress, and the bell, when it switches off, also gets a shake made of four keyframes.

The key and the name

On press the key sinks to PRESS_DEPTH and its shadow tightens; released, it comes back with back.out(3). The name is split into letters: the old ones rise and leave 18 milliseconds apart, the new ones arrive from below on a small spring.

Values to change

NameFileDefaultWhat it changes
STROKEscript.js1.8The thickness of the icon strokes.
MORPH_TIMEscript.js0.6The seconds the change from one icon to the other takes.
OVERSHOOTscript.js1.7How far the strokes go past and come back (0 = no bounce).
PRESS_DEPTHscript.js0.93How much the pressed key sinks (1 = not at all).
AUTOPLAY_GAPscript.js0.7The seconds the fake pointer waits between one key and the next.
ACCENTscript.js'#4f46e5'The colour of the switched-on icon and of the focus ring.

Try them in the Playground

When to use it

For buttons that change state in an app or a site: the phone menu opening and closing, an audio or video player, an item to add to favourites, a finished download, notifications to mute, dark mode. The morphing icon tells what happened without having to read.

On phones

The same animation with adapted sizes: the keys are also measured on the screen height and the two rows of three always fit in the box. A tap does what a click does; the hover growth only happens with a mouse.

With reduced motion

No bending strokes, no sinking keys and no pointer: the icon fades out and comes back already changed, and the name changes with a fade.

Pitfalls

  • The two icons of a pair must have the same number of strokes and every stroke the same number of points, or they cannot be mixed: that is why straight lines are written as curves too.
  • A stroke folded into a point, with round caps, stays a visible dot: it has to be switched off with opacity, not just shortened.
  • With back.out p goes below 0 on the way back: the strokes’ opacity must be kept between 0 and 1, or the browser ignores it.
  • GSAP’s transform on the key would wipe out the CSS one: the light on the top edge is a pseudo-element, so GSAP can move the key without removing it.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 5.1 KB; the libraries: GSAP 28 KB.

Testing

Tested on 25 October 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations