Magnetic Button is a cursor-reactive React button whose surface travels toward the pointer while it hovers, bounded by the configured strength. A second motion value drives the inner label or icon on a different ratio, so the two layers parallax against each other, and on leave both spring back to centre.
Installation
Usage
import { ArrowUpRight } from "lucide-react";
import { MagneticButton } from "@/components/ui/magnetic-button";
export function Example() {
return (
<MagneticButton onClick={() => alert("hi")}>
Say hello
<ArrowUpRight className="size-4" />
</MagneticButton>
);
}Tuning the pull
<MagneticButton strength={28} innerStrength={1.8} stiffness={160}>
View work
</MagneticButton>Props
| Prop | Type | Default | Description |
|---|---|---|---|
strength | number | 18 | How far the button can travel toward the cursor, in pixels. |
innerStrength | number | 1.4 | Inner element drift relative to the outer button. 1 matches; >1 leads the button. |
stiffness | number | 200 | Spring stiffness. Lower = looser. |
damping | number | 15 | Spring damping. Higher = snappier settle. |
innerClassName | string | — | Extra classes for the inner (parallaxed) wrapper. |
className | string | — | Extra classes for the outer button. |
…button | ButtonHTMLAttributes | — | Everything else forwards to the underlying <button> (onClick, disabled, type, aria-*, etc.). |
Related components
- 3D Layered Card
A 3D card with layered effects and animations.
- Animated Code Block
Code snippets with typing and highlighting effects.
- Audio Waveform
A live frequency visualiser for an HTML audio source, driven by WebAudio's AnalyserNode. Bars or waveform mode.
- Bubble Background
An interactive floating bubble animation for backgrounds.
