Magnetic
Wrap anything to make it lean toward the pointer, then spring home when the pointer leaves.
- Category: Inputs
- Licence: Charcoal UI Pro
- Built with: React 19, Tailwind CSS 4, Motion
- Dependencies: motion, clsx, tailwind-merge
Examples
Magnetic
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
strength | number | 0.35 | Share of the pointer offset the element follows. |
range | number | 80 | Pixels outside the element where the pull starts. |
children | ReactNode | — |
About Magnetic
Magnetic wraps any element, usually a button or icon, and makes it drift toward the pointer as it comes near, then spring back when it leaves. It is the small detail that makes a primary call to action feel alive without shouting.
Magnetic is an input component for React 19, styled with Tailwind CSS 4 and animated with Motion. It drops into Next.js, Vite, Remix or Astro through the shadcn CLI as a single file you own.
When to use Magnetic
- The main call-to-action button in a hero section.
- Social icons or nav items in a portfolio footer.
- Floating action buttons that should invite a click.
- Cursor-driven playgrounds and creative landing pages.
How it works
The wrapper measures its child, tracks the pointer within a range around it, and moves the child by a share of the offset through a spring. The strength and range props set how far it follows and from how far away the pull starts.
It is a real form control: it has an accessible name, works with the keyboard alone, shows a visible focus ring and announces its state to screen readers. With prefers-reduced-motion on, it holds still or settles instantly instead of animating.
Customizing Magnetic
Every prop is documented in the API reference above with its type and default. The ones you will reach for first are listed here.
The Customize panel next to the preview lets you change strength, range live, and the Code tab updates to match, so the snippet you copy already carries your values.
- strength (number, default 0.35): Share of the pointer offset the element follows.
- range (number, default 80): Pixels outside the element where the pull starts.
Goes well with Magnetic
These inputs pieces share its tokens and motion language, so they sit together on one page without clashing.
- Color Picker: An animated React swatch colour picker with a ring that glides to the selection
- Rating: An animated React star rating with hover preview and a ripple of popping stars
- File Dropzone: An animated React file dropzone that lifts on hover and lists uploads with progress
- Like Button: An animated React like button: the heart pops, sparks burst and the count rolls
- Hold to Confirm: A React hold-to-confirm button for destructive actions: hold while it fills, let go to cancel
Install Magnetic
npx shadcn@latest add @charcoal/magneticMagnetic is part of Charcoal UI Pro. One seat unlocks all 300 Pro components, 107 landing-page sections and 100 full templates, for every personal and client project, with updates included. Add the @charcoal registry once with your access token, then the command above copies magnetic.tsx into components/ui and installs clsx, tailwind-merge.
You own the file you install: no runtime package, no lock-in, nothing to keep in sync. Change it however your product needs.
See Charcoal UI Pro pricing · Pro setup
Frequently asked questions
- Does it affect click targets or layout?
- No. Only a transform moves, so the element keeps its place in the layout and its full click area. On touch screens and with reduced motion it stays put.
- How do I install Magnetic?
- Magnetic is part of Charcoal UI Pro. Add the @charcoal registry to components.json with your access token, then run npx shadcn@latest add @charcoal/magnetic. It copies magnetic.tsx into components/ui and installs motion, clsx, tailwind-merge.
- Is Magnetic free for commercial use?
- Magnetic needs a Charcoal UI Pro seat, monthly or a one-time lifetime price. A seat covers unlimited personal and commercial projects, including client work, and every future Pro component.
- Does Magnetic work with Next.js?
- Yes. It is a client component for React 19 styled with Tailwind CSS 4, so it works in the Next.js App Router and Pages Router, Vite, Remix and Astro.
- Can an AI coding agent install Magnetic?
- Yes. Connect the Charcoal UI MCP server (https://charcoalui.com/mcp) to Claude Code, Cursor or any MCP client; get_component returns Magnetic's props and get_install_command returns the exact command.