How it works
A transparent sensing area wraps the button. While the pointer moves inside it, the button shifts by pointer-to-center distance × strength, and the label shifts a further 30% for depth. Following uses a 140ms ease-out to feel immediate; leaving uses a 600ms spring. Mouse only: touch and reduced motion do not move it.
Use it for
- The single most important call to action on a landing or campaign page.
- A guiding button inside an empty state.
Look elsewhere when
- Frequent buttons such as form submit or list actions: the movement hurts click accuracy.
- More than one per screen: several moving buttons feel restless.
Usage
import { MagneticButton } from './MagneticButton.jsx'
export function Hero() {
return (
<MagneticButton strength={0.35} onClick={() => startTrial()}>
Try it now
</MagneticButton>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
strength | number | 0.35 | Pull strength from 0 to 1: how far the button follows the pointer. |
radius | number | 28 | Sensing range in px: how close the pointer must be to the button edge before it is pulled. |
variant | 'solid' | 'outline' | 'ink' | 'solid' | Visual style: accent-filled solid, a raised outline with a hairline ring, or ink (text colour, inverts in dark). Each opens a soft 6px halo while pulled. |
...rest | ButtonHTMLAttributes | — | Other attributes go to the <button>, such as onClick and disabled (a disabled button neither pulls nor shows hover). |
Accessibility
- Keyboard focus shows a focus ring and causes no movement.
- Touch devices get no pull.
- With reduced motion the button does not move; hover colour and shadow still appear while the pointer is on it.
Motion
Follow: 140ms ease-out. Return: 600ms spring. Halo opens to 6px and the shadow deepens in 240ms ease-out; a trailing icon leans 2px forward. Press scales to 0.96.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
MagneticButton.jsxmagnetic-button.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





