Code

<!-- magnet-button.free.js: download it from the Install section below and host it with your site -->
<script src="/magnet-button.free.js" defer></script>

<magnet-button strength="0.5" radius="90" size="56" theme="light">Get started</magnet-button>

<!-- with href it is a link -->
<magnet-button href="/pricing" size="56" theme="light">See pricing</magnet-button>

<script>
  document.querySelector('magnet-button').addEventListener('click', () => console.log('clicked'));
</script>

In context

Team plan$24 per seat / monthShared libraries, review links and version history for up to 40 people.
The one action in a card
Sunset, a stronger pull Pro

Install · Free Web Component

One file, no dependencies. Aurora preset, every other option included. Host it yourself so your visitors never load anything from our servers.

1. Install with one command — or download the file
shadcn CLI · React
npx shadcn@latest add https://www.ui-design.co/r/magnet-button.json
2. Load it and use the element
HTML
<!-- magnet-button.free.js: download it from the Install section below and host it with your site -->
<script src="/magnet-button.free.js" defer></script>

<magnet-button strength="0.5" radius="90" size="52" theme="light">Get started</magnet-button>

<!-- with href it is a link -->
<magnet-button href="/pricing" size="52" theme="light">See pricing</magnet-button>

<script>
  document.querySelector('magnet-button').addEventListener('click', () => console.log('clicked'));
</script>
3. React + TypeScript (optional)

The shadcn command adds a typed React wrapper for you. Using the file directly? Custom elements work in React as-is; for type checking add:

TypeScript
// magnet-button.d.ts
declare namespace JSX {
  interface IntrinsicElements {
    'magnet-button': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
      strength?: number | string;
      radius?: number | string;
      size?: number | string;
      href?: string;
      target?: string;
      rel?: string;
      type?: 'button' | 'submit' | 'reset';
      label?: string;
      disabled?: boolean | '';
      theme?: 'light' | 'dark';
      sound?: boolean | '';
    };
  }
}

Pro · React + TypeScript Pro

One payment of $4.99, yours forever. Use it in unlimited personal and commercial projects; no resale.

  • React component (button or link, every native prop passes through) with TypeScript types and the full source
  • Sunset, Mint and Mono tints, plus custom tints from Brand Fit
  • The vanilla Web Component with every tint, a demo page, README and license

Attributes & props

NameTypeDefaultDescription
strength 0..10.5How far the button follows the pointer. 0 turns the pull off and keeps the highlight.
radius number (px)90Reach of the field, measured from the edge of the button. The pull fades to nothing at this distance.
size number (px)52Height; the type and the padding scale with it.
href string—Makes it a link (an <a> inside). target and rel pass through.
type 'button' | 'submit' | 'reset''button'For a button inside a form.
disabled booleanfalseNo pull, no press, dimmed. A disabled link loses its href.
label string—Accessible name when the content is only an icon.
theme 'light' | 'dark''light'White porcelain or dark.
sound booleanoffA porcelain tap on press. Also on for everything inside an element with data-ui-sound="on".
setPoint(x, y) / release() methods—A virtual pointer, in px from the centre of the button, for demos and guided tours. In React it is the point prop.
tint Pro'aurora' | 'sunset' | 'mint' | 'mono' | object'aurora'Colours of the pearl fringe round the highlight, the rim and the light under the button, or a custom tint. Free build ships Aurora only.

The real <button> or <a> is inside the element, so click, Enter and Space, focus and form submission work natively; listen for click as usual. The element itself keeps its place in the layout and only the body inside moves, so nothing around it shifts. Leave free space of about strength × size round the button. The pull is for a mouse or a pen only: on touch screens and with reduced motion the button just sinks when pressed. Every button on a page shares one pointer listener and animates only while it moves. All CSS and a small spring, no WebGL.

More components