Skip to content
animorio
IT
All components

Randomize button

Buttons, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.9 KBGSAP 28 KBFreeDownload the zip

The “Randomize” button of a palette generator: on every tap the die inside the pill hops, makes a turn and changes face, and the five colour stripes renew one after the other from the bottom, with their hex codes rolling. Every stripe has a padlock: the locked colour stays where it is while the others change.

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>
<!--
  "Randomize 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>Randomize 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 Randomize button of a palette generator: the die tumbles inside the pill, the five
         colours change one after the other with their codes rolling, and a locked colour stays -->
    <i class="frame" data-frame aria-hidden="true"></i>
    <div class="rz" data-rz>
      <div class="rz__palette" data-palette role="group" aria-label="Palette">
        <div class="rz__sw" data-sw><i class="rz__wash" data-wash></i><button class="rz__lock" type="button" data-lock aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path class="rz__shackle" d="M5.250 7.250V5.250a2.750 2.750 0 0 1 5.500 0v2"></path><rect x="3.500" y="7.250" width="9" height="6.250" rx="1.800"></rect></svg></button><span class="rz__hex"><b data-outhex></b></span></div>
        <div class="rz__sw" data-sw><i class="rz__wash" data-wash></i><button class="rz__lock" type="button" data-lock aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path class="rz__shackle" d="M5.250 7.250V5.250a2.750 2.750 0 0 1 5.500 0v2"></path><rect x="3.500" y="7.250" width="9" height="6.250" rx="1.800"></rect></svg></button><span class="rz__hex"><b data-outhex></b></span></div>
        <div class="rz__sw" data-sw><i class="rz__wash" data-wash></i><button class="rz__lock" type="button" data-lock aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path class="rz__shackle" d="M5.250 7.250V5.250a2.750 2.750 0 0 1 5.500 0v2"></path><rect x="3.500" y="7.250" width="9" height="6.250" rx="1.800"></rect></svg></button><span class="rz__hex"><b data-outhex></b></span></div>
        <div class="rz__sw" data-sw><i class="rz__wash" data-wash></i><button class="rz__lock" type="button" data-lock aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path class="rz__shackle" d="M5.250 7.250V5.250a2.750 2.750 0 0 1 5.500 0v2"></path><rect x="3.500" y="7.250" width="9" height="6.250" rx="1.800"></rect></svg></button><span class="rz__hex"><b data-outhex></b></span></div>
        <div class="rz__sw" data-sw><i class="rz__wash" data-wash></i><button class="rz__lock" type="button" data-lock aria-pressed="false"><svg viewBox="0 0 16 16" aria-hidden="true"><path class="rz__shackle" d="M5.250 7.250V5.250a2.750 2.750 0 0 1 5.500 0v2"></path><rect x="3.500" y="7.250" width="9" height="6.250" rx="1.800"></rect></svg></button><span class="rz__hex"><b data-outhex></b></span></div>
      </div>
      <button class="rz__btn" type="button" data-go>
        <span class="rz__in">
          <span class="rz__die" data-die><svg viewBox="0 0 20 20" aria-hidden="true"><rect x="2" y="2" width="16" height="16" rx="4.200"></rect><g data-pips><circle cx="6.400" cy="6.400" r="1.350"></circle><circle cx="13.600" cy="6.400" r="1.350"></circle><circle cx="6.400" cy="10" r="1.350"></circle><circle cx="10" cy="10" r="1.350"></circle><circle cx="13.600" cy="10" r="1.350"></circle><circle cx="6.400" cy="13.600" r="1.350"></circle><circle cx="13.600" cy="13.600" r="1.350"></circle></g></svg></span>
          <span class="rz__word">Randomize</span>
        </span>
        <i class="rz__sheen" data-sheen></i>
      </button>
    </div>
    <span class="live" aria-live="polite" data-live></span>

    <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.

10 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 “Randomize 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 rounded band with five colour stripes, from the darkest to the lightest, each with its hex code at the bottom and an open padlock at the top; underneath, a dark pill with a white die and the word “Randomize”. On tap the pill squeezes and comes back on a spring, a light sweeps over it, the die hops, makes a full turn showing other faces and lands with a slight squash on a new face. Meanwhile the stripes change one after the other: the new colour rises from the bottom over the old one, the code rolls and the lettering goes from white to dark when the colour is light. Tapping a padlock closes its shackle and fills it in: that colour is locked, and on the next rolls it stays put (the padlock shakes its head) while the other four change. The palettes come from one hue walking a few degrees at every stripe, often with one far colour as an accent, so they always belong together.

How it works

Palettes that belong together

A seeded generator always gives the same run of numbers. From it come a starting hue, the step it walks from one stripe to the next, a lightness climbing from dark to light and, six times out of ten, one far colour as an accent.

The rising colour

Every stripe carries a veil of the new colour, zero tall and anchored to the bottom: GSAP raises it, staggered from stripe to stripe, and at the end the stripe takes that colour and the veil goes back to zero. The code rolls and the lettering colour is picked from the luminance.

The die and the padlock

The die is a square with seven pips: every face lights some of them. During the turn the face changes three times and the landing squashes it for a moment. A locked stripe skips the change and shakes its padlock.

Values to change

NameFileDefaultWhat it changes
SEEDscript.js7The number the palettes grow from: change it and the run of colours is another one.
SATURATIONscript.js0.62How vivid the colours are.
STAGGERscript.js0.07How many seconds pass between one stripe and the next.
SPRINGscript.js1How much the die and the button bounce.

Try them in the Playground

When to use it

In a design tool, in a generator of palettes, gradients, avatars, names or themes; in a brand or site configurator; anywhere a button offers another random possibility and part of the result should be kept.

On phones

The band is at most 300 pixels wide and at most 132 tall (a third of the screen when it is short), the pill is 50 tall and 172 wide. The padlocks are 30 pixel circles: everything is thumb-sized and nothing depends on hover.

With reduced motion

Colours and codes change at once, the die shows its new face without hopping or turning, the button and the padlocks do not bounce. The demo’s pointer does not start.

Pitfalls

  • The lettering colour on every stripe is worked out from the colour’s luminance: with a fixed colour half the codes would be unreadable.
  • If another roll comes while the veil is still rising, the stripe takes the incoming colour at once and starts again from there.
  • The die turns around its own centre because what turns is the span that holds it, not a piece of the svg.
  • A colour is not told by hue alone: its code is there, and every new palette is read out in an aria-live region.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 28 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