Skip to content
VenusUI
Get started

Magnetic

Wraps any element so it is pulled toward the mouse pointer and springs back.

Preview

Installation

npx shadcn@latest add @venusui/magnetic

Run this in a project set up with shadcn. If you haven’t set it up yet, run npx shadcn@latest init first.

Files added to your project

Paths use the default shadcn aliases. The CLI follows the aliases in your components.json.

  • @/components/ui/magnetic.tsx

Usage

The code behind the preview above.

magnetic-demo.tsx

import { ArrowUpRight } from "lucide-react"

import { Magnetic } from "@/components/ui/magnetic"

export default function MagneticDemo() {
  return (
    <Magnetic>
      <button
        type="button"
        className="inline-flex h-11 items-center gap-2 rounded-full border bg-card px-5 text-sm font-medium transition-colors hover:bg-muted"
      >
        Get in touch
        <ArrowUpRight className="size-4" />
      </button>
    </Magnetic>
  )
}

API reference

PropTypeDefaultDescription
childrenReactNode—The element to make magnetic, e.g. a button. Required.
strengthnumber0.35How far it follows the pointer, from 0 to 1.
rangenumber24Extra space around the element, in pixels, where the pull starts.
classNamestring—Classes for the wrapper.

Only the props above.

Requirements

  • The motion package. The CLI installs it.
  • React 19 and Tailwind CSS v4.

Customization

  • Use a small strength (0.15–0.25) for buttons and a larger one for icons or cursors.
  • Increase range so the pull starts further away from the element.

Accessibility

  • The wrapped element keeps its own role and keyboard behavior; the wrapper adds none.
  • Follows the mouse only, and doesn’t move when the user prefers reduced motion.

Troubleshooting

Nearby elements shift slightly.
The wrapper uses padding plus an equal negative margin to widen the hit area. Reduce range if it overlaps neighbours.
Unknown registry "@venusui"
Your shadcn CLI couldn’t find the namespace in the shadcn registry index. Use the latest CLI (npx shadcn@latest), install by URL, or register it with its address: npx shadcn@latest registry add @venusui=https://venusui.com/r/{name}.json.
No components.json found
Run npx shadcn@latest init in your project first.
Loading preview

Cards whose borders light up near the pointer, as if a light moved across them.

Loading preview

A card with a soft light that follows the pointer.

Loading preview

Cards arranged in a ring that turns in 3D, with buttons, arrow keys and announcements.