Skip to content
animorio
IT
All components

Tip slider

Sliders, Hover, PhysicsGSAP, CSS onlyMediumCompressed weight: Demo 8.2 KBGSAP 28 KBFreeDownload the zip

A café bill, on white: under the subtotal a tip slider that moves freely between the marks and gets pulled in near 10, 15, 18 and 20%, as if by a magnet. On every snap the mark lights up and the handle gives a small bounce; tip and total roll digit by digit, the percentage label chases the handle a beat late, Custom opens a field and Pay confirms with a check. One gesture, in the style of product micro-interactions.

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>
<!--
  "Tip slider" 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 tip slider that snaps to percentages</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>
    <!-- the bill of a café: the tip slider moves freely between the marks and gets pulled in near them,
         like a magnet; tip and total roll, Custom opens a field, Pay confirms with a check -->
    <section class="card" data-card aria-label="Your bill">
      <header class="head">
        <div class="mark" aria-hidden="true">
          <svg viewBox="0 0 24 24"><path d="M6 9h10v4.5a5 5 0 0 1-5 5 5 5 0 0 1-5-5Z"></path><path d="M16 10.5h1.4a2.2 2.2 0 0 1 0 4.4H15.6"></path><path d="M9 4.5c0 1.2 1 1.4 1 2.6M12.4 4.5c0 1.2 1 1.4 1 2.6"></path></svg>
        </div>
        <div class="head__text">
          <p class="head__title">Lindell Café</p>
          <p class="head__meta">Table 7 · 4 items</p>
        </div>
        <p class="head__time">12:40</p>
      </header>

      <div class="row">
        <span class="row__label">Subtotal</span>
        <span class="row__value" data-sub>$39.33</span>
      </div>

      <div class="tip">
        <div class="tip__head">
          <span class="row__label">Tip</span>
          <button class="custom" type="button" data-custom aria-expanded="false">Custom</button>
          <span class="tip__amount roll" data-tipamount aria-live="polite"></span>
        </div>

        <div class="slider" data-slider role="slider" tabindex="0" aria-label="Tip" aria-valuemin="5" aria-valuemax="25" aria-valuenow="15">
          <div class="bubble" data-bubble aria-hidden="true"><span class="bubble__in roll" data-bubbletext></span></div>
          <div class="rail" data-rail>
            <div class="rail__track"><div class="rail__fill" data-fill></div></div>
            <div class="rail__notches" data-notches></div>
            <div class="handle" data-handle><span class="handle__knob" data-knob></span></div>
          </div>
          <div class="marks" data-marks aria-hidden="true"></div>
        </div>

        <div class="field" data-field>
          <label class="field__in">
            <span class="field__label">Custom tip</span>
            <input class="field__input" data-input type="text" inputmode="numeric" maxlength="2" value="22" aria-label="Custom tip in percent">
            <span class="field__unit">%</span>
          </label>
        </div>
      </div>

      <div class="row row--total">
        <span class="row__label">Total</span>
        <span class="total roll" data-total></span>
      </div>

      <button class="pay" type="button" data-pay>
        <span class="pay__fill" data-payfill></span>
        <span class="pay__label" data-paylabel>Pay <span class="roll" data-payamount></span></span>
        <span class="pay__wait" data-paywait aria-hidden="true"><svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="8"></circle></svg></span>
        <span class="pay__done" data-paydone aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M6 12.5l4 4 8-9" pathLength="1"></path></svg>Paid</span>
      </button>
      <p class="note">Tips go to the whole team.</p>
    </section>

    <svg class="ghost" data-ghost viewBox="0 0 24 24" aria-hidden="true"><path d="M5 3.2 19.2 11l-6.3 1.6-3.3 5.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.

27 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 “Tip slider” 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 background there is the white bill card of Lindell Café, table 7, four items: subtotal 39.33 dollars. Below, the Tip row with the amount on the right and the Custom pill, and the slider: a grey track with the green filled part, four thin marks at 10, 15, 18 and 20% with their numbers below, and above the handle a black label with the percentage. Dragging, the handle widens and follows; near a mark it is pulled in, the mark lights up green and the number below turns green, and the handle gives a small bounce. Tip, total and the button amount roll digit by digit, up when they grow and down when they shrink. Let go near a mark, the handle jumps onto it with a spring. Custom opens a field to type the percentage. Pay presses in, shows the bank’s wait, fills with green from the left and draws the check with Paid, then comes back.

How it works

The magnet

The finger moves a raw value; the handle sits on the value bent towards the nearest mark. Within MAGNET points the distance d becomes d times (d over MAGNET) squared: near the mark it shrinks a lot, at the edge of the zone it stays the same, so there is no jump but a pull.

The snap

When the handle is less than a tenth of a point from a mark, the mark grows from the centre with back.out and the handle squashes and comes back with an elastic. Let go within MAGNET points, a spring takes it onto the mark.

Rolling digits

Every character sits in a window one line high: when it changes, the old one leaves upwards and the new one comes in from below, or the other way when the number drops, with a small delay from right to left.

The late label

The label above the handle chases the value with 1 minus e to the minus dt times BUBBLE_LAG on the GSAP ticker: it always arrives a moment later.

Values to change

NameFileDefaultWhat it changes
SUBTOTALscript.js39.33The bill before the tip, in dollars.
STARTscript.js15The starting tip, in percent.
MARKSscript.js10,15,18,20The marks the handle snaps to, in percent.
MAGNETscript.js1.8From how many percentage points away a mark starts pulling the handle.
BUBBLE_LAGscript.js9How quickly the label above the handle catches up with it.
GROWscript.js1.3How much the handle grows while it is held.
ACCENTscript.js#1f8a5bThe colour of the filled part, the lit marks and the payment.

Try them in the Playground

When to use it

In the checkout of a café, a restaurant or a food delivery, in the till of a table-booking app, anywhere a tip is left or a percentage is picked among a few handy choices.

On phones

The card takes the width of the box minus the margins and the slider measures itself again at its real width. With a finger the handle drags as with the mouse, without scrolling the page.

With reduced motion

No bounces or rolling digits: the handle follows at once, the label sits right above it, the digits change in place and the payment goes straight to the check. The autopilot does not start.

Pitfalls

  • The magnet bends the value instead of replacing it: so between marks the handle is free and the finger does not hit a wall.
  • The digits are measured character by character: if the length of the number changes (from 9.99 to 10.00) the windows are rebuilt instead of rolling, so no stray zeros are left in between.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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