Use it for one or two hero actions on expressive pages: agency and portfolio sites, launch pages,
a "get in touch" at the end of a page. It rewards the approach, so it works best with space
around it. Avoid it in dense toolbars, tables and forms, where a moving target is harder to hit;
there use Ripple Button or a plain button.
The motion follows the MotionKit grammar. The action starts before the click: when the pointer
comes within the field around the button, the button eases toward it on the temperament's spring
(it never snaps), and the label trails on a spring 1.6 times slower, so it floats inside the
button. Pressing charges it: it sinks onto its shadow in 90ms with the temperament's squash.
When the pointer leaves, the button settles home with the temperament's bounce. With
elastic, it also stretches along the pull, longer toward the pointer and thinner across.
import { MagneticButton } from "@/components/ui/magnetic-button"export function Hero() { return <MagneticButton size="lg">Start a project</MagneticButton>}
strong (default): follows 40% of the pointer's offset, felt up to 72px around the button.
subtle: 18% within 32px, for navigation bars and secondary actions.
elastic: 32% within 56px, and the button stretches along the pull.
The pull is strongest over the button and fades smoothly to nothing at the edge of the field, so
the button never jumps when the pointer crosses it. It also eases into a cap of half the button's
height, so wide buttons don't slide into their neighbors.
strength (0-1, the share of the pointer's offset from the center) and radius (px around the
button) override the preset:
A native <button type="button"> with a visible focus ring; the label is its accessible name.
The pull is visual only, so the button's hit area never moves out from under a pointer that is
already on it (the pull is a fraction of the distance, always less than the pointer's).
Keyboard focus and presses work as usual; focus never moves the button.
On touch screens, where there is no hover, the button leans toward the finger for as long as it
presses and springs back on release.
With reduced motion (the OS setting or MotionKitProvider reducedMotion="always") the button
stays in place: no pull, label lag, stretch or sink. Hover and focus styles still change, and the
pointer listener is not attached at all.
One passive pointermove listener on the window, attached only while the button is on screen,
the tab is visible and motion is allowed. Each move is read once per frame (one
getBoundingClientRect), then springs run on transform only.
Button and label are driven by motion values; React does not re-render while the pointer moves.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
pointer movement, press
Reduced motion
The button stays in place: no pull, label lag, stretch or sink; hover and focus styles still change.
Keyboard
Tab
Moves focus to the button
Space / Enter
Presses the button (it sinks while the key is down)
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)