Skip to content
animorio
IT
All components

Back to top button

Buttons, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 6.4 KBGSAP 28 KBFreeDownload the zip

The Back to top button of a long article in a made-up baking journal, Field & Loaf, scrolling inside its own window: past the first part of the page the round button springs in bottom right, and a thin ring around the arrow fills with how far down you are. Near the end the ring turns rust and the button opens sideways into a pill that says Top. A click runs the page back up smoothly, the arrow kicks upward, the ring empties backwards and at the top the button tucks itself away. Minimal style, on white.

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>
<!--
  "Back to top button" 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>Back to top button</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/newsreader@5.3.0/opsz.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- a long article of a made-up journal, Field & Loaf, scrolling inside its own window. Past the first screen
         the round Back to top button springs in, bottom right; its thin ring fills with how far down the page you
         are. Near the end the ring turns rust and the button opens sideways into a «Top» pill. A click runs the
         page back up smoothly, the ring empties as it goes and the button tucks itself away at the top. -->
    <div class="reader" data-wrap>
      <div class="reader__bar" aria-hidden="true">
        <span class="reader__brand">Field &amp; Loaf</span>
        <span class="reader__meta">Journal · 6 min read</span>
      </div>

      <div class="page" data-page tabindex="0" aria-label="Article">
        <article class="article">
          <p class="kicker">Baking notes</p>
          <h1>The slow loaf</h1>
          <p class="lede">Most of good bread is waiting. The flour, the water and the salt do the rest, if you let them take the night.</p>

          <h2>Start the evening before</h2>
          <p>Mix four hundred grams of flour with three hundred of water and leave it alone for half an hour. Nothing is happening that you can see, but the flour is drinking, and the dough will be easier to handle for it.</p>
          <p>Add the salt and the starter, pinch them in with wet fingers, and fold the dough over itself four times. Cover the bowl and go and do something else.</p>

          <h2>Fold, then forget</h2>
          <p>Every half hour for two hours, lift one side of the dough and lay it over the rest, turning the bowl a quarter each time. By the last fold it should feel smooth and a little puffed, like a pillow someone has just stood up from.</p>
          <p>Then put it in the fridge overnight. The cold slows the yeast and lets the flavour catch up; this is where a plain loaf turns into a good one.</p>

          <h2>Shape in the morning</h2>
          <p>Tip the dough onto an unfloured board and tighten it into a round with a scraper, pulling it towards you until the skin on top looks taut. Rest it for twenty minutes, then shape it again and lay it seam side up in a floured basket.</p>
          <p>An hour at room temperature is usually enough. Press it gently with a finger: if the dent fills back slowly, it is ready.</p>

          <h2>Bake it hotter than you think</h2>
          <p>Heat the oven and a heavy pot for forty five minutes at the highest setting. Turn the loaf out, score it once with a blade held almost flat, and bake it with the lid on for twenty minutes, then without it until the crust is the colour of chestnuts.</p>
          <p>Let it cool on a rack for an hour before you cut it. It is still baking inside, and the crumb will thank you.</p>

          <p class="sign">With flour on the keyboard, the Field &amp; Loaf kitchen.</p>
        </article>
      </div>

      <button class="top" type="button" data-top aria-label="Back to top" tabindex="-1">
        <span class="top__bg" data-bg aria-hidden="true"></span>
        <span class="top__label" data-label aria-hidden="true"><span>Top</span></span>
        <span class="top__disc" aria-hidden="true">
          <svg viewBox="0 0 48 48" class="top__svg">
            <circle class="ring__track" cx="24" cy="24" r="21"></circle>
            <circle class="ring__run" data-run cx="24" cy="24" r="21" pathLength="1" transform="rotate(-90 24 24)"></circle>
          </svg>
          <svg viewBox="0 0 24 24" class="top__arrow" data-arrow>
            <path d="M12 18V6.5M6.8 11.4 12 6.2l5.2 5.2"></path>
          </svg>
        </span>
      </button>
      <p class="sr" aria-live="polite" data-live></p>
    </div>
  </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.

34 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 “Back to top button” 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

A paper-white window with the bar of the Field & Loaf journal and inside it a long article, «The slow loaf», with its subheadings, scrolling on its own. Past the first sixth of the page, a round white button with a line-drawn arrow arrives bottom right: it rises a few pixels and settles with a bounce. Around the arrow a thin ring fills clockwise as you scroll down, and empties again if you go back up. Near the end of the article the ring turns rust and the button stretches sideways into a pill: the word Top slides in from the left. With the mouse over it the ground swells with an elastic and the arrow lifts a breath; pressed, the ground squashes. On click the arrow kicks upward, the page runs back up smoothly, starting slow and braking at the top, the ring empties backwards as you climb, the pill closes and, at the top, the button tucks itself away towards its corner. A wheel or a finger during the run stops it and hands the page back to the reader.

How it works

The page-position ring

An SVG circle with pathLength=1 and stroke-dasharray 1 1, turned -90 degrees once in its transform attribute: nothing rotates, only stroke-dashoffset changes, set to 1 minus the page position (scrollTop over how far it can scroll). gsap.quickTo makes it follow 0.32 seconds behind, so it never jitters.

Appear, open, tuck away

Past SHOW the button rises 14 pixels with back.out; under 0.6 of SHOW it hides (the double threshold keeps it from flickering on the edge). Past END GSAP widens the button to OPEN pixels on a spring, the word Top slides in from the left and the ring fades to rust. GSAP only moves the button (size and visibility); the ground and the arrow are separate children, so hover never fights its tweens.

The run back up

No jumping scrollTo: an object goes from scrollTop to 0 in RETURN seconds with power3.inOut and writes scrollTop at every step. The duration grows a little with the distance. During the run the ring follows the real scroll and empties; at the top the button tucks away to 0.4. A real wheel or finger stops the run.

Values to change

NameFileDefaultWhat it changes
SHOWscript.js0.16How far down the page the button appears
ENDscript.js0.9How far down the ring turns rust and Top opens
RETURNscript.js1.1The seconds of the run back up
SPRINGscript.js1How much the button bounces as it appears
OPENscript.js92The width of the open pill, in pixels
READscript.js5.2The seconds of the scroll down when the demo runs by itself
IDLEscript.js1The seconds before the demo starts by itself
--rugginestyle.css#c4572eThe ring colour near the end

Try them in the Playground

When to use it

At the bottom of any long page: a blog post, a recipe, documentation, a product list, terms of use. The ring also tells how much is left, without a progress bar across the top of the page.

On phones

Same animations; on touch there is no hover, the press is there, and a finger on the page during the run stops it. The window is at most 86% of the screen tall and the button stays 48 pixels, easy for a thumb.

With reduced motion

The button fades in and out, no spring; on click the page fades, goes back to the top and reappears, no run; the ring follows the scroll with no lag. The demo does not move by itself.

Pitfalls

  • The ring must not spin: the -90 degrees go in the circle’s transform attribute, once, and only stroke-dashoffset is animated (with autoRound off, or it snaps to 0 or 1).
  • GSAP widening the button and the hover swelling it must not share an element: the button for GSAP, the ground and the arrow for the hover.
  • Showing and hiding at the same threshold makes the button flicker on the edge: two thresholds, SHOW to appear and 0.6 of SHOW to hide.
  • The hand-made run back up must stop on a real wheel or finger, or it fights the reader.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, Newsreader (font variabile) 5.3.0.

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

Testing

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