uiniverse

animations

MagneticHover

Makes child elements subtly follow the cursor within bounds, creating a magnetic pull effect on hover.

v1.0.0react >=18next >=14tailwind >=4motion >=12
hovercursormagneticinteractivemicro-interaction

Preview

Loading preview...

Props

PropTypeDefaultDescription
children*ReactNodeContent to apply the magnetic effect to
strengthnumber0.3Pull strength toward cursor (0-1)
radiusnumber200Activation radius in pixels
disabledbooleanfalseDisable the magnetic effect
classNamestringAdditional Tailwind classes
idstringHTML id attribute

Slots

SlotTypeRequiredDescription
childrenReactNodeYesThe element that will magnetically follow the cursor on hover

Layout

Display: inline-block
Responsive: No

Wraps children in an inline-block animated div. The element moves within its bounding box without affecting document flow.

Examples

Basic magnetic button

<MagneticHover>
  <button className="rounded-lg bg-white px-6 py-3 text-black font-semibold">
    Get Started
  </button>
</MagneticHover>

Strong pull on an icon

<MagneticHover strength={0.6}>
  <div className="flex h-16 w-16 items-center justify-center rounded-full bg-neutral-800">
    <ArrowIcon />
  </div>
</MagneticHover>

Subtle nav link

<MagneticHover strength={0.15}>
  <a href="/docs" className="text-neutral-400 hover:text-white transition-colors">
    Documentation
  </a>
</MagneticHover>

Disabled state

<MagneticHover disabled>
  <button className="rounded-lg bg-neutral-700 px-6 py-3 text-neutral-400 cursor-not-allowed">
    Unavailable
  </button>
</MagneticHover>

AI Usage Hint

Use MagneticHover to make buttons, icons, or cards subtly follow the cursor. Great for CTAs and interactive elements. Set strength (0-1) to control pull intensity.

Works Well With

ShimmerButtonGlowCard