Skip to content
animorio
IT
All components

Rent split slider

Sliders, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.6 KBGSAP 28 KBFreeDownload the zip

A flat’s rent split between three flatmates on a single bar: three orange stretches with initials and percentage, and two white dividers to drag. Moving a divider widens and narrows the two stretches beside it, the percentages and the three dollar shares change as you drag and the sum always stays the rent; “Equal” and “By room size” send the dividers back to their place on a 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>
<!--
  "Rent split 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>Rent split 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">
    <!-- the rent split between three flatmates on one bar: two dividers to drag, the shares rolling
         and the total staying put -->
    <section class="rs" data-rs aria-label="Split the rent">
      <header class="rs__head"><strong>Split the rent</strong><span data-outtotal>$2,400 a month</span></header>
      <div class="rs__bar" data-bar>
        <div class="rs__part" data-part="0"><b>AK</b><i data-outpct>40%</i></div>
        <div class="rs__part" data-part="1"><b>JO</b><i data-outpct>32%</i></div>
        <div class="rs__part" data-part="2"><b>MI</b><i data-outpct>28%</i></div>
        <button type="button" class="rs__grip" data-grip="0" role="slider" aria-label="Divider between Aiko and Jonas" aria-valuemin="15" aria-valuemax="70" aria-valuenow="40"><i></i></button>
        <button type="button" class="rs__grip" data-grip="1" role="slider" aria-label="Divider between Jonas and Mira" aria-valuemin="30" aria-valuemax="85" aria-valuenow="72"><i></i></button>
      </div>
      <ul class="rs__who">
        <li><span>Aiko</span><strong data-outsum>$960</strong></li>
        <li><span>Jonas</span><strong data-outsum>$768</strong></li>
        <li><span>Mira</span><strong data-outsum>$672</strong></li>
      </ul>
      <footer class="rs__foot">
        <button type="button" class="rs__chip" data-preset="size" aria-pressed="true">By room size</button>
        <button type="button" class="rs__chip" data-preset="equal" aria-pressed="false">Equal</button>
        <span class="rs__note"><span data-outnote>Adds up to $2,400</span></span>
      </footer>
    </section>
    <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.

26 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 “Rent split 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 white, a rounded card: “Split the rent” and on the right “$2,400 a month”. Below, a tall bar split in three stretches, from full orange to the lightest, each with initials (“AK”, “JO”, “MI”) and its percentage; between one stretch and the next a white divider. Under the bar, three columns: “Aiko $960”, “Jonas $768”, “Mira $672”. At the bottom two pills, “By room size” (chosen) and “Equal”, and the line “Adds up to $2,400”. On entering the dividers start from the middle and spring open. Dragging a divider, with a finger or the mouse, changes the width of the two stretches beside it, percentages and shares update at every point and nobody goes below 15 percent; on release the divider gives a small bounce. With the arrow keys it moves one point at a time. “Equal” sends the two dividers to one third and two thirds on a spring, and the shares become “$800” each.

How it works

Two numbers do it all

The state is the position of the two dividers as percentages. The three widths, the three percentages and the three shares come from them; dragging, using the keyboard or picking a preset changes only those two numbers.

The drag

Each divider captures the pointer on touch: the finger’s position on the bar becomes a whole percentage, kept between the minimum of whoever is on the left and of whoever is on the right.

The sum always adds up

The first two shares are rounded to the dollar, the third takes what is left of the rent: that way the three amounts always add up to the total, even with three thirds that do not.

The presets

“Equal” and “By room size” animate the two numbers to their values on an elastic spring, redrawing the bar on every frame; the pill lights up by itself whenever the dividers sit on those values.

Values to change

NameFileDefaultWhat it changes
ACCENTscript.js#ff6a3dThe colour of the bar (the three shades come from it).
RENTscript.js2400The monthly rent to split.
MINscript.js15Everyone’s minimum share, as a percentage.
SPRINGscript.js1How much the dividers bounce when you let go or pick a preset.
LOOPscript.jstrueLeft alone, the demo’s pointer drags the dividers and then starts again.

Try them in the Playground

When to use it

In a household expenses app or one for finding flatmates, when rent is not split equally because the rooms are not equal; the same three-way bar with two dividers carries a budget across three lines, a project’s time across three phases, three partners’ stakes or a portfolio’s allocation.

On phones

The card is at most 344 pixels wide and about 250 tall, and narrows with the screen. Every divider has a touch area 28 pixels wide and 60 tall, larger than the visible bar, and the bar does not scroll the page while you drag.

With reduced motion

Dragging works the same; the presets put the dividers in place at once, with no spring, and there is no bounce on release. On entering the bar is already split. The demo’s pointer does not start.

Pitfalls

  • The dividers are two real sliders (role slider) with a minimum and maximum that change with the other divider, and an aria-valuetext giving the two shares they touch: they work with arrows, Page Up and Page Down.
  • Three shares each rounded on its own can add up to a dollar more or less than the rent: the last one is worked out by difference. The same goes for the percentages, which must make 100.
  • The bar has touch-action none, otherwise on a phone the horizontal drag is taken by page scrolling and the divider stops after a few pixels.
  • Names, rent and room sizes are invented.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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