Magnetic Button
ComponentsButtonsMagnetic Button
Buttons

Magnetic Button

A tactile button with a soft magnetic pull. Go on, get a little closer.

React + CSS
AN INVITATION TO INTERACT
Move your pointer. Feel the pull.
Live component. Go ahead, interact.
01

Installation

Run this in your shadcn-configured React project. The component and stylesheet are added together.

TERMINAL
npx shadcn@latest add http://localhost:5173/r/magnetic-button.json

This command uses the current site address. For localhost, keep this preview running on the same computer. Files follow your configured components alias.

02

Usage

Import the component and make the details your own.

TypeScript
import { MagneticButton } from '@/components/anticraft/MagneticButton';

export function Example() {
  return <MagneticButton strength={0.2}>Make your move ↗</MagneticButton>;
}
03

Props

PropTypeDefaultDescription
childrenReactNode—The button label and optional decorative content.
strengthnumber0.2How far the surface follows the pointer, clamped between 0 and 1.
disabledbooleanfalseDisables the button and resets its position.
type'button' | 'submit' | 'reset''button'The native button type.
classNamestring''Additional classes for the button. Native button attributes and event handlers are supported.
04

Motion & accessibility

Considered by default.

Pointer movement runs only on a fine pointer with hover support. Reduced motion, touch input, keyboard focus, and disabled state keep the surface still.

Use semantic content and meaningful labels in your composition. Check contrast and keyboard behavior with your own styles and content.