NK

Search

Search pages, posts, and components

All components

Magnetic Button

Buttons

A button magnetically attracted to the cursor while hovered.

Installation

Add it with the shadcn CLI:

$pnpm dlx shadcn@latest add https://nawalkattel.com.np/r/magnetic-button.json
Or install manually
  1. 1. Install dependencies

    pnpm add motion clsx tailwind-merge
  2. 2. Copy the component source into components/library/magnetic-button.tsx

Props

PropTypeDefaultDescription
strengthnumber0.4How strongly the button follows the cursor (0-1).
onClick() => void - Click handler.

Accessibility

  • Pointer-only motion - keyboard focus and activation are unaffected.
  • Returns to rest on mouse leave, so it never drifts away.
  • A real <button> underneath the motion wrapper.

Dependencies

motionclsxtailwind-merge