Spring micro-interactions in React with zero animation libraries

You do not need a 40KB animation runtime to ship interruptible springs, gliding pills, morphing status buttons or tactile physics in React 19 and Tailwind v4. Here is the exact 240Hz shared-frame spring engine powering 16 free Hairline UI components—plus live demos you can test and install with one shadcn CLI command.

animation libraries added
0 KB
fixed-step spring physics
240 Hz
free MIT spring components
16
reduced-motion documented
12/16

01Live feel

Interrupt them mid-flight

Click rapidly between tabs, ring the bell twice before it settles, or cycle the status button. Everything below runs on DOM-direct springs and CSS transitions—zero animation packages.

Liquid tabs — switches tabs mid-flight while preserving momentum and stretching along the velocity vector.
Notification bell — impulses stack onto the spring's live angular velocity.
Status button — width, icon and text morph smoothly on one surface.

02The engine

60 lines of fixed-step spring physics

Every spring on the page shares one requestAnimationFrame loop that sleeps the moment the last spring rests. onFrame writes directly to element styles so React never re-renders 60 times a second.

ui-interaction-motion.ts
const SPRING_STEP = 1 / 240; // fixed physics step: stable at 60Hz, 120Hz and throttled mobile CPUsconst running = new Set<{ step: () => void }>();const painters = new Set<() => void>();let raf = 0, last = 0, spare = 0;function tick(now: number) {  // Clamp hidden-tab gaps so returning to a tab never explodes velocity  spare += Math.min((now - last) / 1000, 0.05);  last = now;  while (spare >= SPRING_STEP) {    running.forEach((s) => s.step());    spare -= SPRING_STEP;  }  const batch = [...painters];  painters.clear();  batch.forEach((paint) => paint());  raf = running.size ? requestAnimationFrame(tick) : 0; // 0% CPU once settled}export function createSpring(initial: number, cfg: { stiffness: number; damping: number; mass?: number }, onFrame: () => void) {  let value = initial, velocity = 0, target = initial;  const { stiffness, damping, mass = 1 } = cfg;  const node = {    step() {      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;      value += velocity * SPRING_STEP;      if (Math.abs(value - target) < 0.01 && Math.abs(velocity) < 0.1) {        value = target; velocity = 0; running.delete(node);      }      painters.add(onFrame);    },  };  return {    get: () => value,    set(next: number) { target = next; running.add(node); if (!raf) { last = performance.now(); raf = requestAnimationFrame(tick); } },    push(v: number) { velocity += v; running.add(node); if (!raf) { last = performance.now(); raf = requestAnimationFrame(tick); } },  };}

Want to dial in stiffness, damping or generate a pure CSS linear() curve visually? Open our free Easing & springs tool to test curves on real UI and copy CSS, Tailwind v4, WAAPI or SwiftUI code.

03Installable pieces

16 free components built on this pattern

Every item installs as readable TypeScript into your components folder, bringing ui-interaction-motion.ts automatically when needed.

Interruptible physics & gestures6

Surfaces that keep their momentum when redirected mid-flight or dragged past a boundary.

  • Liquid tabs

    Tabs whose highlight has a little surface tension: it draws out and pinches for a moment, then it is a pill again.

  • Notification bell

    A bell that behaves like one: each notification hits it, a burst rings harder, and the clapper lags behind on its own.

  • Folder

    A project tile that holds your actual files: it opens on a hinge, fans real sheets, and takes a dropped file with weight.

  • Reactions

    Emoji reactions for comments and messages: press, slide along the tray and let go, and the emoji flies into its chip.

  • Drop zone · Membrane

    A drop zone whose border is a membrane: it reaches for the file, holds it, swallows it and passes it through to its row.

  • Slide to send

    The confirm step of a payment: carry the thumb to the person you are paying and the money drains into their avatar.

State & value morphing6

Text, numbers and action states that transform on one surface instead of flashing or resizing abruptly.

  • Status button

    Save, Saving, Saved: the spinner opens in, the check draws itself, errors shake, and the label morphs between them.

  • Text morph

    Text that changes the way it should: shared letters slide over, new ones rise out of a blur, the width eases.

  • Number roll

    Numbers that change like an odometer: every digit rolls in the direction the number moved.

  • Delete with undo

    One call on any element: it folds in half and in half again, turns edge-on and is gone. unfold() brings it back.

  • Add to cart

    One call throws the product into the cart on a real arc; it drops in below the rim and the cart dips with the weight.

  • Merge button

    Merge a pull request and see it go in: the button carries a small branch graph, and pressing it draws what your merge strategy really does to main.

Tactile dials & hold triggers4

Physical resistance, detents and deliberate confirmation curves built with pointer events and springs.

  • Hold to confirm

    A deliberate action, held for a moment: the ring fills, the label changes, and confirmation settles into a check.

  • Hold to start

    A card whose main action is held: light gathers toward your finger while you hold, and bursts across the card when it starts.

  • Level dial

    A 270° dial for one level in a card: drag it and it follows, and when a preset sets it a crest of light spreads from its centre as the arc sweeps there.

  • Passkey button

    A biometric passkey button whose 9-ridge fingerprint scans optically ridge by ridge while pending, then sweeps an 8×8 Bayer wave across the pill as the ridges draw into a check.

Try one right now in any shadcn/ui project

$ npx shadcn@latest add @hairline/liquid-tabs

04Performance

Five mistakes that make React springs feel janky

Tested at 4× CPU slowdown on phone widths—where hidden React re-renders show up immediately.

  • Avoid

    Calling setState() inside requestAnimationFrame

    Do instead

    Re-rendering a React tree 60–120 times per second triggers reconciliation jank on mid-range phones. Keep spring state in refs and mutate transform/opacity directly inside onFrame.

  • Avoid

    Using raw frame delta (dt) directly in spring integration

    Do instead

    A single 80ms GC pause or backgrounded tab can make semi-implicit Euler integration diverge. Clamp elapsed time to 50ms and step in fixed 1/240s substeps.

  • Avoid

    Interrupting a CSS cubic-bezier mid-transition

    Do instead

    Duration curves reset velocity to zero on retargeting, which feels sticky when switching tabs rapidly. A velocity-preserving spring curves smoothly from its current motion into the new target.

  • Avoid

    Leaving timers or rAF loops running off-screen

    Do instead

    Stop ticking automatically when velocity and displacement drop below epsilon, and pause continuous effects whenever IntersectionObserver reports the element off-screen or document.hidden is true.

  • Avoid

    Ignoring prefers-reduced-motion

    Do instead

    Under reduced motion, skip spring travel and jump straight to the resting value (or cross-fade opacity cleanly) so state changes stay legible without vestibular discomfort.

05Questions

Before you install

Why skip Framer Motion or React Spring for UI micro-interactions?

Full animation libraries are great for complex shared-layout choreography, but shipping 35–50KB of runtime JavaScript just for button presses, gliding tabs and number rolls adds bundle weight and upgrade churn. A ~60-line shared-rAF spring integrator plus CSS linear() covers 95% of product UI interactions with zero extra dependencies.

When should I use CSS linear() instead of a JS spring?

Use CSS linear() for simple two-state transitions that do not depend on drag velocity (hover lifts, toggles, focus rings). Use a JS spring like createSpring when the user can drag, flick or rapidly interrupt a control mid-flight, such as liquid tabs, bells, or range scrubbers.

How do I tune spring stiffness and damping quickly?

Start with stiffness 360 and damping 28 for crisp UI snaps, or open our free Easing & springs tool to tune by duration and bounce and copy the exact CSS linear() or physics numbers.

Are all the components in this guide free and MIT licensed?

Yes. Every component listed here lives in the public @hairline shadcn registry under the MIT license and installs straight into your repo with npx shadcn@latest add @hairline/<name>.

06Keep going

Where to go next

Tune your own curves in our free Easing & springs editor, browse all free React components, or explore standalone landing page blocks.