Skip to content
animorio
IT
Back to the library

Coin flip

Physics, HoverGSAP, CSS onlyMediumCompressed weight: Demo 6.0 KBGSAP 28 KBFreeDownload the zip

Tossup, a small made-up app that settles things with a coin: tap it and the brass coin rises spinning, slows as it falls, bounces twice, wobbles on its edge and settles on Heads or Tails, its shadow shrinking and growing underneath. The result writes itself letter by letter and the tally rolls. Hand-written physics, minimal style, GSAP.

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>
<!--
  "Coin flip" 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>Coin flip</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- Tossup, a small made-up app that settles things with a coin: the coin rises spinning, falls, bounces twice,
       wobbles on its edge and settles on Heads or Tails; the result writes itself and the tally rolls -->
  <main class="stage">
    <section class="app" aria-label="Tossup, a coin flip">
      <header class="head">
        <p class="brand">Tossup</p>
        <h1 class="question">Who picks the film tonight?</h1>
      </header>

      <div class="arena" data-arena>
        <div class="shadow" data-shadow aria-hidden="true"></div>
        <div class="tilt" data-tilt>
          <div class="lift" data-lift>
            <button class="coin" type="button" data-coin aria-label="Flip the coin">
              <span class="coin__rim" data-rim aria-hidden="true"></span>
              <span class="coin__face" data-face aria-hidden="true">
                <svg viewBox="0 0 200 200">
                  <defs>
                    <radialGradient id="brass" cx="38%" cy="32%" r="78%">
                      <stop offset="0" stop-color="var(--brass-hi)" />
                      <stop offset=".55" stop-color="var(--brass)" />
                      <stop offset="1" stop-color="var(--brass-lo)" />
                    </radialGradient>
                    <linearGradient id="sheen" x1="0" y1="0" x2="0" y2="1">
                      <stop offset="0" stop-color="#fff" stop-opacity="0" />
                      <stop offset=".5" stop-color="#fff" stop-opacity=".55" />
                      <stop offset="1" stop-color="#fff" stop-opacity="0" />
                    </linearGradient>
                    <clipPath id="disc"><circle cx="100" cy="100" r="97" /></clipPath>
                  </defs>
                  <circle cx="100" cy="100" r="98" fill="var(--brass-lo)" />
                  <g data-knurl></g>
                  <circle cx="100" cy="100" r="86" fill="url(#brass)" />
                  <circle cx="100" cy="100" r="79" fill="none" stroke="var(--brass-lo)" stroke-opacity=".55" stroke-width="1.2" />
                  <circle cx="100" cy="100.8" r="79" fill="none" stroke="#fff" stroke-opacity=".35" stroke-width=".8" />

                  <g class="side" data-heads>
                    <g class="relief">
                      <g transform="translate(100 86)">
                        <circle r="17" fill="none" stroke="var(--brass-lo)" stroke-width="4" transform="translate(.9 1.1)" opacity=".5" />
                        <circle r="17" fill="none" stroke="var(--brass-deep)" stroke-width="4" />
                        <g data-rays stroke="var(--brass-deep)" stroke-width="4" stroke-linecap="round"></g>
                      </g>
                      <text x="100" y="140" text-anchor="middle" class="coin__word">HEADS</text>
                    </g>
                  </g>
                  <g class="side" data-tails>
                    <g class="relief">
                      <path d="M112 62 a28 28 0 1 0 0 48 a22 22 0 1 1 0 -48 z" transform="translate(.9 1.1)" fill="var(--brass-lo)" opacity=".5" />
                      <path d="M112 62 a28 28 0 1 0 0 48 a22 22 0 1 1 0 -48 z" fill="var(--brass-deep)" />
                      <text x="100" y="140" text-anchor="middle" class="coin__word">TAILS</text>
                    </g>
                  </g>

                  <g clip-path="url(#disc)"><rect data-sheen x="-20" y="-40" width="240" height="70" fill="url(#sheen)" /></g>
                </svg>
              </span>
            </button>
          </div>
        </div>
      </div>

      <div class="result" aria-live="polite">
        <p class="result__word" data-word>Tap the coin</p>
        <p class="result__note" data-note>&nbsp;</p>
      </div>

      <p class="tally" data-tally aria-label="Tally">
        <span>Heads <span class="num" data-count="heads"></span></span>
        <span class="tally__sep" aria-hidden="true"></span>
        <span>Tails <span class="num" data-count="tails"></span></span>
      </p>
    </section>
  </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.

24 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 “Coin flip” 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

Tossup is a small made-up app for settling small things: at the top the question, «Who picks the film tonight?», and below it a brass coin with a knurled edge, a raised sun on Heads and a moon on Tails. Tap it (or wait a few seconds) and the coin rises spinning: the spin is a scaleY that passes through the thickness of the rim, and the face changes halfway. Rising, the spin slows; falling, it lands with a small squash, bounces twice, lower each time, wobbles on its edge and settles. Underneath, the shadow shrinks and fades as the coin rises and fills back in when it lands. A sheen runs across the face as it spins. The result, Heads or Tails, writes itself letter by letter with who picks the film, and the tally at the bottom rolls digit by digit. With the pointer over it, the coin leans a little towards it.

How it works

A spin without 3D

The coin turns about the horizontal axis with a phase: the face’s scaleY is the absolute cosine, never below 0.04, and when the cosine is negative the other face shows. Under the face sits a darker disc, the rim, offset by the sine times the thickness: halfway through the spin you see the edge.

The flight

Height is a parabola, 4u(1−u), and the phase heads for its target on an ease-out: the spin slows by itself. The target is always a whole number of turns plus half a turn if the face must change, so the coin lands square on the result chosen in advance.

Bounces and wobble

Two lower bounces, the second a third of the first, with the phase swinging a little around the target; then the wobble on the edge, a sine damped by e to the −5.5t on the phase and the rotation. On every impact the coin squashes for a moment on an elastic spring.

Shadow and sheen

The shadow is a soft ellipse that shrinks and fades with height; the sheen is a light band clipped to the disc that slides with the sine of the phase.

One clock

Everything moves on gsap.ticker, the result writes itself by counting letters and the self-flip is a delayedCall: no setTimeout.

Values to change

NameFileDefaultWhat it changes
SPEEDscript.js1Speed of the whole toss.
SPINSscript.js4Whole turns in the air.
AIRscript.js1.15Seconds in the air.
HEIGHTscript.js0.82How high it goes, as a share of the room above the coin.
BOUNCEscript.js0.12Height of the first bounce.
WOBBLEscript.js0.55How much it wobbles on its edge.
TILTscript.js7Degrees of lean towards the pointer.
HOLDscript.js2.2Seconds held before it flips by itself.

Try them in the Playground

When to use it

For an app that helps you decide, a game, a draw, an event page with a small prize or a light moment inside a product.

On phones

The same coin, sized on the screen height; a tap makes the toss.

With reduced motion

No flight and no bounces: the face changes with a fade and the result appears.

Pitfalls

  • A scaleY of zero makes the coin vanish and the highlights jump: keep it above 0.04 and show the rim underneath.
  • The jump height is measured in pixels from the room above the coin: it must be recomputed on resize.
  • The final phase is chosen before the toss, a whole number of turns plus half a turn if needed: otherwise the coin stops on its edge.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

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

Testing

Tested on 1 December 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