Skip to content
animorio
IT
All components

Undo redo button

Buttons, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 4.8 KBGSAP 28 KBFreeDownload the zip

An editor’s Undo and Redo in a single pill. In the middle the name of the last action, at the sides how many steps can be undone and how many redone. Press Undo and the arrow turns backwards once, the name rolls to the one before and a step hops over the label from one count to the other. Hold to rewind everything; when nothing is left the button shakes its head.

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>
<!--
  "Undo redo button" 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>Undo redo button</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">
    <!-- the Undo and Redo of an editor in one pill: the arrow turns back, the name of the action rolls,
         and one step hops across from the undo count to the redo count; hold to rewind -->
    <div class="ur" data-ur role="group" aria-label="History">
      <button class="ur__btn" type="button" data-undo aria-label="Undo">
        <svg viewBox="0 0 22 22" aria-hidden="true"><path d="M6 8h7.200a4.300 4.300 0 0 1 0 8.600H9M9.200 4.800 6 8l3.200 3.200"></path></svg>
      </button>
      <span class="ur__count ur__roll" aria-hidden="true"><span data-ucount>5</span></span>
      <span class="ur__label ur__roll"><span data-label>Add shadow</span></span>
      <span class="ur__count ur__roll" aria-hidden="true"><span data-rcount>0</span></span>
      <button class="ur__btn" type="button" data-redo aria-label="Redo">
        <svg viewBox="0 0 22 22" aria-hidden="true"><path transform="matrix(-1 0 0 1 22 0)" d="M6 8h7.200a4.300 4.300 0 0 1 0 8.600H9M9.200 4.800 6 8l3.200 3.200"></path></svg>
      </button>
      <span class="ur__say" data-say aria-live="polite"></span>
    </div>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.200 19.200 11l-6.300 1.600-3.300 5.900Z"></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

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

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 “Undo redo button” 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 white, a light grey pill sixty pixels tall: on the left the white disc of Undo, on the right Redo’s, between them the name of the last action, “Add shadow”, and beside each disc a small number: 5 steps to undo, 0 to redo. Tap Undo and the arrow turns backwards once, the disc bounces, the name rolls to “Resize image”, and a small blue “1” leaves the left count, hops in an arc over the label and lands in the right one: 4 and 1. Redo does the same the other way, its arrow turning forwards. Hold and the steps go one after another while there are any; at zero the label says “Nothing to undo”, the disc dims and, if you insist, shakes its head. It also works with Ctrl or Cmd plus Z, and with Shift to redo.

How it works

A single number

Everything the pill says comes from how many actions are still done: the two counts, the name in the middle, which button is off and what screen readers hear.

The step that hops

An element made on the spot travels from the starting count to the other: x is linear, y is a sine, so it draws an arc over the label, and halfway it is smaller.

The arrow turns the right way

The whole icon rotates 360 degrees around its own centre: backwards for Undo, forwards for Redo. The direction tells which way time goes without reading.

Press and hold

Pointerdown fires one step, after nearly half a second the repeat starts with GSAP’s delayedCall; it stops on release, if the pointer leaves or when the steps run out.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#4f63f5The colour of the step that hops from one side to the other.
DONEscript.js5How many actions are already done at the start (0 to 5).
REPEATscript.js0.16While holding, how many seconds between one step and the next.
HOPscript.js26How high, in pixels, the step hops over the label.
LOOPscript.jstrueLeft alone, the demo’s pointer undoes, redoes and then holds to rewind everything.

Try them in the Playground

When to use it

In an editor’s toolbar: a design app, a page builder, a spreadsheet, a photo or text editor. Wherever undoing is frequent and it helps to know how many steps are left.

On phones

The same pill, 284 pixels wide: the two discs are 44, easy on a thumb, and holding does not open the system menu.

With reduced motion

Numbers and name change at once, the arrow does not turn and the step does not hop; holding works the same. The demo does not move by itself.

Pitfalls

  • The five actions are made up: in a real editor the list is its history, and a new action after an Undo clears what could be redone.
  • A truly disabled button gets no focus and cannot say why it does nothing: here it stays active with aria-disabled and answers with a shake.
  • Ctrl or Cmd plus Z should be caught only where it makes sense: here inside the pill, in an editor on the canvas, never on text fields that have their own Undo.
  • On iPhone a long press opens the system menu: -webkit-touch-callout: none and touch-action: none on both buttons.
  • If the button loses focus or the pointer is cancelled while holding, the repeat must be stopped, or it carries on by itself.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 21 November 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 components