Skip to content
animorio
IT
Back to the library

Before and after bars

SVG, HoverGSAP, CSS onlyMediumCompressed weight: Demo 5.4 KBGSAP 28 KBFreeDownload the zip

The results block in a portfolio case study: three numbers, each with its bar, and a Before / After control. Switching to after the bars go to the new value on a spring and leave a thin mark where they were, the numbers count, a chip with the change springs in next to each and everything takes the lime green. Hovering a row brings back what it was before.

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>
<!--
  "Before and after bars" 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>Case study results with before and after bars</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 results block of a portfolio case study: three numbers, each with a bar; switching from before to after
         the bars move on a spring to the new value and leave a thin mark where they were, the numbers count, and a
         small chip with the change springs in next to each; hovering a row brings back what it was before -->
    <section class="card" data-card data-view="before" aria-label="Case study results">
      <span class="card__glow" aria-hidden="true"></span>
      <header class="head">
        <div>
          <p class="head__kicker">Case study, Harbor &amp; Pine</p>
          <h1 class="head__title">Checkout, redesigned</h1>
        </div>
        <div class="seg" data-seg role="group" aria-label="Show">
          <span class="seg__pill" data-pill aria-hidden="true"></span>
          <button type="button" data-view-btn="before" aria-pressed="true">Before</button>
          <button type="button" data-view-btn="after" aria-pressed="false">After</button>
        </div>
      </header>

      <ul class="rows">
        <li class="row" data-row data-before="2.1" data-after="2.9" data-max="3.4" data-kind="percent" data-delta="+38%">
          <div class="row__top"><span class="row__name">Conversion rate</span><span class="row__chip" data-chip><span>+38%</span></span><span class="row__value"><span data-value>2.1%</span></span></div>
          <div class="row__bar"><span class="row__fill" data-fill></span><span class="row__mark" data-mark></span></div>
          <p class="row__was" data-was>was 2.1%</p>
        </li>
        <li class="row" data-row data-before="220" data-after="125" data-max="240" data-kind="time" data-delta="−43%">
          <div class="row__top"><span class="row__name">Time to check out</span><span class="row__chip" data-chip><span>−43%</span></span><span class="row__value"><span data-value>3:40</span></span></div>
          <div class="row__bar"><span class="row__fill" data-fill></span><span class="row__mark" data-mark></span></div>
          <p class="row__was" data-was>was 3:40</p>
        </li>
        <li class="row" data-row data-before="71" data-after="56" data-max="100" data-kind="whole" data-delta="−15 pts">
          <div class="row__top"><span class="row__name">Cart abandonment</span><span class="row__chip" data-chip><span>−15 pts</span></span><span class="row__value"><span data-value>71%</span></span></div>
          <div class="row__bar"><span class="row__fill" data-fill></span><span class="row__mark" data-mark></span></div>
          <p class="row__was" data-was>was 71%</p>
        </li>
      </ul>
    </section>
    <p class="sr" data-live aria-live="polite"></p>

    <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 “Before and after bars” 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

In the middle, on black, a dark card: at the head the project name, ‘Checkout, redesigned’, and on the right a control with Before and After. Below, three rows: the metric’s name, the big number on the right and a bar. At the start you see the before: the grey bars grow from zero one after the other with a small bounce, the numbers climb to 2.1%, 3:40 and 71%. Tapping After the control’s pill slides on a spring and turns lime green, a lime halo lights up in the card’s corner, and one row at a time the bars go to the new value: the conversion one lengthens, the other two shorten, slightly overshoot the point and settle, turning lime. Where the bar used to end a thin white mark stays. The numbers count to 2.9%, 2:05 and 56%, and next to each a chip with the change springs in: +38%, −43%, −15 pts. Hovering a row its background lightens and under the bar ‘was 2.1%’ appears. Going back to Before everything returns. Left alone, a pointer switches to after, reads two rows and goes back to before.

How it works

The data in the rows

Each row has in the HTML the before value, the after value, the maximum of its scale and the kind (percentage with one decimal, time in minutes and seconds, whole percentage). The script reads everything from there.

Bar and number, two curves

For each row an object holds the value and the bar’s fraction. The bar gets there with elastic.out, which overshoots and returns; the number with power2.out, which never overshoots: a number going past and coming back would look like a mistake.

The mark of before

A dash 14 pixels tall sits at the percentage of the before value: it shows only in the after, so you see how far the bar has travelled.

The colour of after

The grey bar has a lime layer on top with zero opacity: the card takes data-view="after" and the CSS brings it to one in half a second, together with the control’s pill and the halo.

The chips

Each chip comes in from 14 pixels lower and scale 0.7 with elastic.out, three tenths after its bar; it leaves upwards when going back to before.

Values to change

NameFileDefaultWhat it changes
STARTscript.jsbeforeWhat is shown at the start: before or after.
SPRINGscript.js0.9How long the bars’ spring lasts, in seconds.
COUNTscript.js0.9In how many seconds the numbers reach the new value.
STAGGERscript.js0.09The delay between one row and the next, in seconds.
ACCENTscript.js#b9f06cThe colour of after.
PAUSEscript.js2.6By itself: how many seconds it stays on after before looking at the rows.
LOOPscript.jstrueLeft alone, a pointer switches from before to after.

Try them in the Playground

When to use it

At the end of a case study in the portfolio of a designer, a developer or an agency, where you say what changed after the work. Also good on a landing page to show clients’ results, or in a report.

On phones

The same card, as wide as the screen: title and control tighten a little and on a short screen the rows sit closer. A tap on a row shows the before value.

With reduced motion

No springs and no counting: bars and numbers go straight to the new value, the chips appear already in place and the colours change with a fade.

Pitfalls

  • Two metrics out of three improve by going down: the after colour means ‘after’, not ‘more’, and the chip gives the direction with its sign.
  • The bar on a spring can go below zero for a frame if the value is small: the scale is kept at zero as a minimum.
  • The numbers of a real case study must come from the client’s data: these are invented.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 14 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 animations