---
title: "Magnetic Button"
description: "Free React magnetic button that pulls toward the cursor and springs back on leave. Off on touch devices and with reduced motion. Framer Motion, shadcn install."
category: "Components"
parent: "https://beui.dev/components/motion/button"
publishedAt: "2026-05-17"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/components/motion/button/magnetic"
markdown: "https://beui.dev/components/motion/button/magnetic.md"
license: "MIT"
---

# Magnetic Button

> Free React magnetic button that pulls toward the cursor and springs back on leave. Off on touch devices and with reduced motion. Framer Motion, shadcn install.

## Install

```bash
npx shadcn@latest add @beui/button-magnetic
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

### Magnetic Button usage

Button composed with the Magnetic wrapper for cursor-attracted pull.

```tsx
"use client";

import { ArrowRight } from "lucide-react";
import { MagneticButton } from "@/components/motion/button";

export function ButtonMagneticPreview() {
  return (
    <div className="flex flex-wrap items-center justify-center gap-4">
      <MagneticButton variant="primary" size="md" strength={0.35}>
        Hover me
        <ArrowRight className="h-4 w-4" />
      </MagneticButton>
      <MagneticButton variant="secondary" size="md" strength={0.25}>
        Subtle pull
      </MagneticButton>
      <MagneticButton variant="outline" size="md" strength={0.5}>
        Strong pull
      </MagneticButton>
    </div>
  );
}
```

## API Reference

### MagneticButton

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `size` | `"sm" \| "md" \| "lg" \| "icon"` | — | No | Height and padding; "icon" is a square icon-only button. Default: "md" |
| `variant` | `"outline" \| "primary" \| "secondary" \| "ghost"` | — | No | Visual style: filled, card, ghost or outline. Default: "primary" |
| `pressScale` | `number` | — | No | Scale while pressed. Default 0.97: subtle, so the press reads as feedback, not a squash. |
| `ripple` | `boolean` | — | No | Spawn a Material-style ripple from the press point. Off by default. |
| `sound` | `boolean` | — | No | Play a soft press sound. Off by default; a `SoundProvider` can mute it app-wide. |
| `strength` | `number` | `0.25` | No | Magnetic pull strength. Default 0.25. |
| `magneticClassName` | `string` | — | No | Class applied to the magnetic wrapper. |

## More in Button

- [Metallic Button](https://beui.dev/components/motion/button/metallic.md)
- [Base Button](https://beui.dev/components/motion/button/base.md)
- [Stateful Button](https://beui.dev/components/motion/button/stateful.md)

## Source

- Registry detail: https://beui.dev/r/button-magnetic
- Raw source: https://beui.dev/r/button-magnetic/raw
- GitHub: https://github.com/starc007/ui-components
