Skip to content
animorio
IT
All components

Mortgage payment calculator

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

A mortgage calculator in a card: dragging the years, the monthly payment is recounted and a bar split in two shows how much of what you pay back is the loan and how much is interest. More years, lower payment and wider interest: you see it in one gesture.

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>
<!--
  "Mortgage payment calculator" 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>Mortgage payment calculator with the years to drag and the share of interest that widens</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">
    <!-- a mortgage calculator: dragging the years, the monthly payment is recounted and the bar shows how much of
         what you pay back is the loan and how much is interest -->
    <section class="mg" data-mg aria-label="Mortgage calculator">
      <header class="mg__head">
        <span class="mg__title">Monthly payment</span>
        <span class="mg__terms" data-terms></span>
      </header>
      <p class="mg__pay"><b data-pay></b><i>a month</i></p>

      <div class="split" aria-hidden="true"><span class="split__loan" data-loan></span><span class="split__int" data-int></span></div>
      <div class="legend">
        <span class="legend__item">Loan <b data-loanv></b></span>
        <span class="legend__item legend__item--int">Interest <b data-intv></b></span>
      </div>

      <div class="yrs" data-yrs>
        <div class="yrs__track" aria-hidden="true"><span class="yrs__fill" data-fill></span><span class="yrs__ticks" data-ticks></span></div>
        <span class="yrs__thumb" data-thumb aria-hidden="true"><span class="yrs__bubble"><span data-years></span></span><span class="yrs__knob" data-knob></span></span>
        <input class="yrs__input" data-input type="range" min="10" max="30" step="1" aria-label="Years to repay">
      </div>
    </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.

15 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 “Mortgage payment calculator” 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 black, a dark card: at the top “Monthly payment” and the terms (€240k at 3.6% fixed), then the large payment, a bar in two pieces (the loan in mint green on the left, the interest in grey stripes on the right) with the two figures below, and at the bottom the slider of the years from 10 to 30 with notches every five and a tag that follows the knob. On opening the payment counts from zero and the bar opens. Dragging the knob, the tag says the years, the payment and the interest count at once with no spring, while the point where the bar splits moves and settles with a small bounce. The knob grows when grabbed and the tag lifts. Underneath there is a real range input: arrows and screen readers work.

How it works

The formula

Payment = loan × r / (1 − (1 + r)^−n), with r the monthly rate and n the months. From it the total interest (payment × n − loan) and the loan’s share of the total paid back, which is the width of the green piece.

Two speeds

Knob, payment and interest follow the finger with power3.out in 0.3 seconds, no spring: a number never overshoots. The split of the bar instead settles with back.out(2.2) in 0.7: that is where the motion tells the change.

The real input

A transparent input type=range covers the track; the drawn knob and tag sit in an element GSAP moves in x. aria-valuetext says years and payment.

Values to change

NameFileDefaultWhat it changes
LOANscript.js240000How much is borrowed, in euros.
RATEscript.js3.6The fixed yearly rate, in percent (made up).
YEARSscript.js25The years chosen at the start, from 10 to 30.
ACCENTscript.js#5ee6b0The colour of the loan in the bar.
LOOPscript.jstrueLeft alone, a pointer drags the years.

Try them in the Playground

When to use it

On the site of a bank, a broker or an estate agency, on the page of a home for sale, in any simulator where one knob changes both the payment and the total cost (financing, leasing, long-term rentals).

On phones

The same card, as wide as the screen; the payment drops down to 38 pixels. The slider is dragged with a finger (touch-action: pan-y lets the page scroll vertically).

With reduced motion

Numbers, bar and knob go straight to their value, with no counting and no bounces.

Pitfalls

  • The knob’s position is worked out in pixels from the slider’s width: it must be recalculated on resize, because the preview box changes size while you look at it.
  • Two tweens on the same object (numbers and the bar’s split): only the first has overwrite, or the bar’s spring would be stopped at every step.
  • The interest is in grey stripes, not a second colour: the accent stays one and it reads without colour too.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

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