Magnetic Button

Button that subtly follows the cursor with a magnetic effect.

Open in v0

Last updated: January 29, 2026

Move your cursor near the buttons to see the magnetic effect

Installation

pnpm dlx shadcn add @smoothui/magnetic-button
npx shadcn@latest add @smoothui/magnetic-button
yarn dlx shadcn add @smoothui/magnetic-button
bunx shadcn add @smoothui/magnetic-button

Features

  • Cursor-following magnetic effect
  • Configurable strength and activation radius
  • Spring physics for natural movement
  • Respects reduced motion preferences
  • Touch device detection (effect disabled on touch)
  • Disabled state support
  • Polymorphic with asChild prop
  • GPU-accelerated transforms

Props

Usage

import MagneticButton from "@/components/magnetic-button";

export default function Example() {
  return (
    <MagneticButton strength={0.3} radius={150}>
      Hover near me
    </MagneticButton>
  );
}

Examples

Default

<MagneticButton>Click me</MagneticButton>

Custom Strength

Increase the magnetic pull strength (0-1):

<MagneticButton strength={0.5}>Strong magnetic effect</MagneticButton>

Custom Radius

Adjust the activation radius in pixels:

<MagneticButton radius={200}>Large activation area</MagneticButton>

Custom Spring Config

Fine-tune the spring animation:

<MagneticButton springConfig={{ duration: 0.6, bounce: 0.2 }}>
  Bouncy
</MagneticButton>

As Child (Polymorphic)

Use with any component using asChild:

<MagneticButton asChild>
  <a href="/docs">Go to Docs</a>
</MagneticButton>