Magnetic Button

Button that magnetically follows the cursor; the label leans a little further for parallax, with a spring press state. Solid, accent and glass surfaces.

Try it: Move near the button — it pulls toward you. Press to feel the spring.

Installation

Install with the shadcn CLI:

npx shadcn@latest add https://www.framekitui.live/r/magnetic-button.json

Or, with the @framekit namespace registered: npx shadcn@latest add @framekit/magnetic-button. You can also copy the source into components/ui/magnetic-button.tsx (view on GitHub).

Usage

import { MagneticButton } from '@/components/ui/magnetic-button'

Props

Component props
PropTypeDefaultNotes
strengthnumber0.35How far the button follows the pointer (fraction of the offset).
variant'solid' | 'accent' | 'glass''solid'Surface style.
...propsButtonHTMLAttributes—Forwarded to the button.

Dependencies

  • motion

See all 24 Buttons components