Documentation
Buttonsbuttonmagnetichover

Magnetic Button

A button that magnetically follows the cursor on hover.

Installation

Terminal
1npx shadcn@latest add "https://sniper-ui-coral.vercel.app/r/magnetic-button.json"

Auto-Installed Dependencies

The CLI will automatically install these packages.

Terminal
1npm install framer-motion clsx tailwind-merge

Usage

Basic

page.tsx
1import { MagneticButton } from "@/components/ui/magnetic-button"; 2 3export default function MyPage() { 4 return ( 5 <MagneticButton> 6 Click me 7 </MagneticButton> 8 ); 9}

Examples

examples.tsx
1import { MagneticButton } from "@/components/ui/magnetic-button"; 2 3export default function MyPage() { 4 return ( 5 <div className="flex gap-4"> 6 {/* Default strength */} 7 <MagneticButton>Default</MagneticButton> 8 9 {/* Stronger pull */} 10 <MagneticButton strength={80}>Strong Pull</MagneticButton> 11 12 {/* Custom styled */} 13 <MagneticButton className="rounded-full px-6"> 14 Rounded 15 </MagneticButton> 16 </div> 17 ); 18}

Props

PropTypeDefaultDescription
childrenReact.ReactNodeThe button content.
classNamestringAdditional CSS classes to apply.
strengthnumber40Controls how strongly the button follows the cursor. Higher = more movement.