Skip to content

Open Magnetic Button with its live demo →

Magnetic Button

A button that gently follows the pointer for a magnetic feel.

Usage

Copy src/MagneticButton.tsx into your React project. No extra dependencies.

tsx
import { MagneticButton } from "./MagneticButton";

export function Example() {
  return <MagneticButton>Get started</MagneticButton>;
}

Props

PropTypeDefaultWhat it does
strengthnumber0.35How far the button follows the pointer, from 0 (still) to 1
classNamestringExtra class on the button

Notes

  • Client component ("use client")
  • Uses pointer move within a small radius around the button
  • Respects prefers-reduced-motion