Skip to content
animorio
IT
All components

Trick or treat button

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

The Trick or treat button of a Halloween party, on black, in a minimal style: a single idea, a carved slit. Hovering it, a thin cut shaped like a pumpkin’s eye opens inside the pill and an orange candlelight flickers through it, warming the edge. On click the pill squashes and springs back, the light flares, the label turns into Treat and a wrapped sweet, drawn in two lines, jumps out of the slit and lands on the button’s edge.

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>
<!--
  "Trick or treat 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>The Trick or treat button with candlelight in the slit</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" data-stage>
    <!-- one idea: a carved slit. On hover a thin pumpkin-eye slit opens in the pill and candlelight flickers
         through it; on click the light flares, the label turns to Treat and a wrapped sweet jumps out and lands -->
    <section class="door" data-door aria-label="Trick or treat at Hollow Lane">
      <p class="door__head"><span class="door__name">Hollow Lane</span><span class="door__date">Oct 31 · from 7 pm</span></p>

      <div class="door__wrap" data-wrap>
        <span class="glow" data-glow aria-hidden="true"></span>
        <button class="btn" type="button" data-btn aria-pressed="false">
          <span class="btn__fill" aria-hidden="true"><span class="btn__warm" data-warm></span></span>
          <span class="btn__row">
            <span class="slit" data-slit aria-hidden="true">
              <svg viewBox="0 0 28 18">
                <defs>
                  <clipPath id="occhio"><path d="M4.2 15.4C2.6 13.2 4.4 10.6 8.4 9.2L25.6 2.4C23.4 9.6 17 14.8 4.2 15.4Z"></path></clipPath>
                  <radialGradient id="fiamma" cx="40%" cy="70%" r="75%">
                    <stop offset="0" stop-color="#fff1c9"></stop>
                    <stop offset="0.35" stop-color="#ffb24a"></stop>
                    <stop offset="0.8" stop-color="#ff7a1a"></stop>
                    <stop offset="1" stop-color="#8a2e00"></stop>
                  </radialGradient>
                </defs>
                <g clip-path="url(#occhio)">
                  <rect class="slit__dark" x="0" y="0" width="28" height="18"></rect>
                  <g data-lid><rect class="slit__light" data-light x="0" y="0" width="28" height="18" fill="url(#fiamma)"></rect></g>
                </g>
                <path class="slit__edge" data-edge d="M4.2 15.4C2.6 13.2 4.4 10.6 8.4 9.2L25.6 2.4C23.4 9.6 17 14.8 4.2 15.4Z"></path>
              </svg>
            </span>
            <span class="btn__labels">
              <span class="btn__label" data-label="trick">Trick or treat</span>
              <span class="btn__label btn__label--treat" data-label="treat">Treat</span>
            </span>
          </span>
        </button>

        <svg class="sweet" data-sweet viewBox="0 0 44 22" aria-hidden="true">
          <g data-sweet-body>
            <path class="sweet__twist" d="M9 11 2.5 5.2 3.6 11 2.5 16.8Z"></path>
            <path class="sweet__twist" d="M35 11 41.5 5.2 40.4 11 41.5 16.8Z"></path>
            <rect class="sweet__wrap" x="9" y="4.5" width="26" height="13" rx="6.5"></rect>
            <path class="sweet__stripe" d="M17 4.9 13.6 17.1M24 4.6 20.6 17.4M31 4.9 27.6 17.1"></path>
            <path class="sweet__shine" d="M13 7.6h6"></path>
          </g>
        </svg>
        <span class="sweet__shadow" data-shadow aria-hidden="true"></span>
      </div>

      <p class="door__hint"><span data-hint="a">Knock, if you dare</span><span data-hint="b">One sweet per visitor</span></p>
    </section>

    <svg class="ptr" data-ptr viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2v15.6l4.3-4.1 2.8 6.3 2.6-1.1-2.8-6.2h5.9Z"></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.

20 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 “Trick or treat 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 a black background, slightly lighter in the middle, there are the name of a made-up street, Hollow Lane, with Oct 31 · from 7 pm underneath, the dark Trick or treat pill and a grey line: Knock, if you dare. To the left of the label, inside the pill, there is a thin closed line. Hover it and the line springs open into a cut shaped like a pumpkin’s eye, a triangle with a curved base, and inside an orange candlelight comes on, paler at the bottom, flickering slightly and rising and falling by half a pixel; the same light warms the inside of the pill on the slit’s side, the edge catches a thread of orange and the dark around the button warms a little. On click the pill squashes and springs back, the light flares and then settles, Trick or treat rises away and Treat, in peach, comes up from below, and a wrapped sweet, drawn as an orange outline with stripes and two twisted ends, jumps out of the slit spinning, makes an arc and lands on the button’s top edge: it squashes, rocks once and leaves a small warm glow underneath. The line below becomes One sweet per visitor. A second click sends the sweet back into the slit and Trick or treat returns. A drawn pointer does it all by itself and stops at the first real touch.

How it works

A single slit, cut out

The pumpkin eye is a path in a clipPath: inside sits the dark and over the dark a rectangle with a radial candle gradient, paler at the bottom. Opening the slit means scaling it in height from a tenth to one, from the bottom, with back.out.

The light is a number

A level from zero to one that the states aim at (closed, open, rewarded), multiplied by how open the slit is and by a flicker made of three out-of-phase sines. The same number drives the light in the slit, the glow inside the pill, the edge and the halo outside.

The flare on click

The level rises to 1.6 in seven hundredths and comes back to one in nearly a second: the candle flares and settles. Meanwhile the pill squashes for nine hundredths and springs back with elastic.out.

The sweet’s jump

The sweet starts small in the middle of the slit and goes to the button’s top edge on an arc worked out by hand: x linear, y with a sine as high as SALTO, the spin unwinding to zero. On landing it squashes from below and rocks once.

The labels never meet

Trick or treat and Treat sit in the same grid cell: the first leaves upwards with a blur, the second comes in from below a moment later. So the button keeps its width and the two words are never read together.

Values to change

NameFileDefaultWhat it changes
ETICHETTAscript.js"Trick or treat"The button’s label.
PREMIOscript.js"Treat"The label after the click.
SFARFALLIOscript.js0.35How much the candlelight flickers in the slit.
APERTURAscript.js0.55How long the slit takes to open, in seconds.
SALTOscript.js64How high the sweet jumps, in pixels.
VAMPAscript.js1.6How bright the light flares on click before settling.

Try them in the Playground

When to use it

In a Halloween party invitation, on a sweet shop’s page at the end of October, on a seasonal offer button, on a site that dresses up for the night for a week.

On phones

The same pill, shorter if the screen is short. Without a mouse the first tap opens the slit and presses at once: the light comes on and the sweet jumps straight away.

With reduced motion

The slit opens without a spring, the light neither flickers nor flares, the labels swap with a fade and the sweet appears already resting on the edge, without a jump. The drawn pointer does not run.

Pitfalls

  • The slit must be scaled from its bottom point: scaled from the centre it would open up and down at once and look like a yawning mouth, not an eye opening.
  • The two labels must sit in the same grid cell: one above the other, the button would change height on every click.
  • The sweet’s start and landing are measured on every jump with getBoundingClientRect: the pill changes size with the screen and an arc worked out at the start would end off the edge.
  • The flicker must not be random tweens one after another: three out-of-phase sines added together give a flame that never repeats exactly and never jumps.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 30 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 components