Skip to content
animorio
IT
All components

Price range slider

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

The price filter of a made-up lamp shop, on very light grey: a histogram of thin bars with the products per price band, and below it the track with two round handles. Dragging them, the bars inside the range light up and the ones outside fade, the Min and Max fields and the product count roll to the new numbers, and when the handles touch they push each other away on a small spring.

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>
<!--
  "Price range 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 two-handle price range slider</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 price filter of a lamp shop: drag the two handles, the bars inside the range light up,
         the fields and the product count roll to the new numbers -->
    <section class="card" data-card aria-label="Price filter">
      <header class="head">
        <div>
          <p class="head__title">Price</p>
          <p class="head__meta"><span data-shop>Lumenhall</span> · desk and floor lamps</p>
        </div>
        <button class="reset" type="button" data-reset>Reset</button>
      </header>

      <div class="chart">
        <div class="bars" data-bars aria-hidden="true"></div>
        <div class="track" data-track>
          <div class="track__rail"></div>
          <div class="track__fill" data-fill></div>
          <div class="handle" data-handle="0" role="slider" tabindex="0" aria-label="Minimum price"></div>
          <div class="handle" data-handle="1" role="slider" tabindex="0" aria-label="Maximum price"></div>
        </div>
      </div>

      <div class="fields">
        <div class="field" data-field="0">
          <span class="field__label">Min</span>
          <span class="field__value"><span class="field__cur" data-cur>$</span><span class="roll" data-roll="min"></span></span>
        </div>
        <span class="fields__dash" aria-hidden="true"></span>
        <div class="field" data-field="1">
          <span class="field__label">Max</span>
          <span class="field__value"><span class="field__cur" data-cur>$</span><span class="roll" data-roll="max"></span></span>
        </div>
      </div>

      <button class="show" type="button" data-show>
        Show <span class="roll roll--light" data-roll="count"></span> products
      </button>
    </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.

26 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 “Price range 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 a white card with wide corners and a soft shadow: at the top Price and the line Lumenhall · desk and floor lamps, a small Reset on the right. Below, a histogram of thirty-six thin bars, taller in the price bands with more lamps, and under it the track with two round white handles with a black centre, one at each end. Grabbed, a handle grows a little and its shadow spreads, and the field with its price lights up; dragged, it follows the finger on a short spring, the stretch of track between the two handles fills, the bars inside the range light up in black while the ones outside fade to grey and sink slightly. The Min and Max fields under the track show the prices with rolling digits, and the Show 197 products button rolls to the new count too. Let go, the handle runs on a little by inertia and settles on a multiple of five. The two handles never cross: when one pushes against the other they always stay forty dollars apart, the other backs off by a hair and returns on a small spring. The drawn autopilot pointer takes the minimum to 60, the maximum to 220 (about 130 products), pushes the minimum into the maximum, takes it back and presses Reset.

How it works

Bars from products

The products per band are one number per bar, a soft hump around the middle prices with a fixed seed, so the demo is the same on every visit. Each bar’s height is its count over the highest one, and the product count is the sum of the bars inside the range, counting bands cut by a handle in proportion.

Two handles on a spring

Each handle has a price, a velocity and a goal. On every frame of the GSAP ticker a spring carries it towards the goal: stiffer while dragging, softer when it settles. The goal never crosses the other handle minus MIN_GAP.

Pushing apart

If their speed brings the two handles closer than MIN_GAP, the overlap is shared between them and the pushed one gets a small backwards velocity: it backs off by a hair and its spring brings it back.

Inertia and the snap

Let go, the handle’s goal becomes its price plus an eighth of a second of its velocity, rounded to STEP: the handle runs on a little and settles on a clean price.

Rolling digits

Each digit is a 0 to 9 column inside a one-line window; when the number changes every column slides to its digit with back.out, the ones on the right a moment earlier, and the thousands comma stays still.

Values to change

NameFileDefaultWhat it changes
SHOPscript.jsLumenhallThe made-up shop in the line under the title.
CURRENCYscript.js$The currency symbol in the two fields.
MAX_PRICEscript.js400The highest price on the track.
STEPscript.js5The step the price snaps to when the handle settles.
MIN_GAPscript.js40The minimum distance between the two handles, in the currency.
BARSscript.js36How many bars the histogram has.
ACCENTscript.js#18181bThe colour of the lit bars, the track and the button.
SPRINGscript.js1How stiff the handles’ spring is.

Try them in the Playground

When to use it

For the filters of an online shop, a property or travel site, a catalogue: anywhere you pick a range of prices, square metres or dates and need to see at once how many results are left.

On phones

The card takes the width of the box minus the margins and the track is measured on its real width; with a finger the handles drag without scrolling the page, and tapping the track moves the nearest handle.

With reduced motion

No springs, bounces or rolling digits: the handles go straight where they are put, the numbers change at once and the autopilot does not run; the card fades in with a range already picked.

Pitfalls

  • The spring runs on the GSAP ticker with its deltaTime, not performance.now(): that way it stops and starts with the page and keeps time in recordings too, and the step is capped at 34 milliseconds.
  • Dragging uses setPointerCapture on the track, not on the handle: that way tapping the track grabs the nearest handle and the finger does not lose it when it leaves the circle.
  • A handle’s goal is limited against the other handle’s goal, not its position: otherwise, while the other bounces, the two chase each other.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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