Spring

A draggable element tied to its place by a spring coil, which pulls it back on release.

Drag
"use client"

import {
  Spring,
  SpringElement,
  SpringProvider,
} from "@animate-ui/react/primitives/spring"

export default function SpringDemo() {
  return (
    <SpringProvider>
      <Spring className="z-10 text-muted-foreground" />
      <SpringElement className="relative z-20">
        <div
          aria-label="Drag me"
          className="flex size-14 items-center justify-center rounded-full bg-primary text-sm font-medium text-primary-foreground shadow-md select-none"
        >
          Drag
        </div>
      </SpringElement>
    </SpringProvider>
  )
}

Installation

npm install @animate-ui/react motion
pnpm add @animate-ui/react motion
yarn add @animate-ui/react motion
bun add @animate-ui/react motion

Usage

import {
  Spring,
  SpringElement,
  SpringProvider,
} from '@animate-ui/react/primitives/spring';

export function Avatar() {
  return (
    <SpringProvider>
      <Spring className="text-muted-foreground" />
      <SpringElement>
        <img src="/avatar.png" alt="Avatar" draggable={false} />
      </SpringElement>
    </SpringProvider>
  );
}

Add draggable={false} to images inside SpringElement, so the browser's native drag image doesn't take over the drag.

Animation

  • Dragging stretches a coil between the element's place and the element. The coil tightens as it stretches.
  • On release, the element springs back with a bounce, the coil following it.
  • Spring is a full-viewport SVG that never catches the pointer.
  • Under reduced motion, the element is back in place at once on release.

API Reference

SpringProvider

PropTypeDefault
transition?
SpringOptions{ stiffness: 200, damping: 16 }
pathConfig?
SpringPathConfig{}
children
React.ReactNode-

SpringPathConfig

PropTypeDefault
coilCount?
number8
amplitudeMin?
number8
amplitudeMax?
number20
curveRatioMin?
number0.5
curveRatioMax?
number1
bezierOffset?
number8

Spring

The coil. Its color is currentColor.

PropTypeDefault
...props?
React.SVGProps<SVGSVGElement>-

SpringElement

PropTypeDefault
asChild?
booleanfalse
children
React.ReactElement-
...props?
Omit<HTMLMotionProps<'div'>, 'children'>-

useSpring

Returns the spring state: the x/y and springX/springY motion values, isDragging / setIsDragging, the coil path and childRef.

Credits

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/18/2026

On this page