Skip to content

Magnetic

Free

Any item leans toward a mouse that comes near and springs home when it leaves. Magnetic Layer moves a part more or less than the item.

  • Base UI
  • Motion
  • React 19
  • Tailwind CSS 4

Added Nov 9, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

Wrap one child, and put a MagneticLayer around a part that must move more than the item, such as the arrow.

The sample also uses Button. One command adds them with this item:

start-trial-button.tsx

Magnetic

<div>
PropTypeDefaultDescription
strengthnumber—The share of the pointer distance from the center that the item moves: 0.3 moves it 3px for each 10px. The pull grows with the size, so lower it for a large item (0.06 for a card). In a row, the item reaches past its edge toward the pointer (about 16px for a 140px button at 0.3): keep the gap to a neighbour larger, or lower strength or range, or it covers the neighbour.
rangenumber—How far outside the edge the pull starts, in px. 0 pulls only while the pointer is on the item.
axis"both""x""y"—x or y moves the item on one axis only (a nav link that must stay on its line).
disabledbooleanfalseSprings the item home and stops the pointer work.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

MagneticLayer

<div>
PropTypeDefaultDescription
depthnumber2How far the layer moves, as a multiple of the item pull: 2 moves it twice as far as the item (an icon that floats ahead), 1 with the item, 0 keeps it still on the page, and below 0 it moves against the pull.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.
  • Wrap one child. The child keeps its own look, focus ring, press, and clicks.
  • Lower strength for a large item: 0.3 suits a button, about 0.06 a card.
  • Use axis="x" or axis="y" for a link that must stay on its line.
  • Put MagneticLayer inside the child for an icon that moves depth times the pull.
  • For an item that turns in 3D toward the mouse, use Tilt.
  • For a plain action with no effect, use a Button.

Decoration only: it adds no role, no name, and no focus stop. The child keeps its own.

On a touch screen only a finger pressed on the item pulls it, so a finger elsewhere on the page never moves it, and a tap still lands on the item.

Pull and return
glide · spring (stiffness 700, damping 53), the item follows the pointer and springs home
  1. AddedMagnetic.
Open the release