Platform
VaultVault
  • Free15
  • Navigation19
  • Buttons9
  • Scroll55
  • Text27
  • Sliders & marquees19
  • Gallery & images67
  • Cursor24
  • Page transitions10
  • Loaders2
  • Backgrounds10
  • UI components33
ButtonsPart of ProButtons
IconsPart of ProIcons
  • Interface Essentials144
  • Social Icons69
  • Payment Badges41
SavedPart of ProSaved
Support
DocumentationDocumentation
MCP serverMCP server
SettingsSettings
VaultButtonsMagnetic Button
Ink Fill Logo HoverBrowse all 182Pixel Dissolve Button
  • Free15
  • Navigation19
  • Buttons9
  • Scroll55
  • Text27
  • Sliders & marquees19
  • Gallery & images67
  • Cursor24
  • Page transitions10
  • Loaders2
  • Backgrounds10
  • UI components33
  • Interface Essentials144
  • Social Icons69
  • Payment Badges41
Sign inSign in

Start free. The code for 15 components, no card needed.

Get 15 free

Magnetic Button

This one is locked. Become a member to open the code for it and the rest of the Vault.

See plansTry the 15 free ones

What you'll need.

Install

  • gsap

Setup

npm i gsap

More like this

  • Elastic
  • Fill
  • Magnetic

Features.

  • A round fill rises up through the pill on hover and carries on out of the top on leave
  • The pill leans towards the pointer and the label leans a little further, so the text floats inside its shape
  • Springs back with an elastic settle when the pointer leaves
  • Two variants: a solid orange pill with a cream fill, and a orange hairline outline, also with a cream fill
  • The label colour swaps to the ink colour in step with the fill
  • Quick in-and-out never stutters: each fill move takes over from the last
  • Keyboard focus plays the fill; touch taps just follow the link
  • No pull on small screens (540px and below)
  • Respects prefers-reduced-motion: no pull, the fill and colour switch instantly
  • GSAP only, plain CSS for the look

How to get it right.

Keep the pull small

25px at the edge reads as magnetic; past 40 the button starts to feel loose and can drift out from under the pointer. Leave room around it so the pill has space to move.

Let the label lead

The label travels on top of the pill's move, so with the defaults it shifts 28px in total at the edge. Set data-au-label-strength="0" for a pill that moves as one block, or raise it for more depth.

Pick a fill with contrast

The fill sits under the label, so --mgb-ink has to read on --mgb-fill. If you change one, check the other.

Pair the variants

Use primary for the one action that matters and outline beside it for the second. Both share the same size and motion, so they sit together without fuss.

Variations.

  • Primary — the default: solid orange pill, cream fill, dark label throughout
  • Outline — data-au-variant="outline": orange hairline pill, cream fill rising through it
  • Still — data-au-strength="0" and data-au-label-strength="0" for the fill alone
  • Floaty label — data-au-strength="8" and data-au-label-strength="20": the pill barely moves, the text drifts inside it
  • Your colours — override --mgb-bg, --mgb-text, --mgb-fill, --mgb-ink and --mgb-border on the button

Where it fits.

  • Hero call to action — one primary next to an outline, the pair this demo shows
  • Contact or footer — a single large "Get in touch" that invites a hover
  • Case study end — "Next project" as the last thing on the page
  • Pricing — the plan you want picked as primary, the rest as outline

Frequently asked.

Yes. Keep the class, the root attribute and the two inner spans; give the button type="button" and border: 0 (the outline variant draws its border with a shadow, not a border).

The label doesn't wrap by design. The pill grows with the text; if it sits in a narrow column, shorten the copy or lower the button's font-size.

Set font-size on the button. Everything inside is in em, so the pill, label and radius scale together.

Each [data-au-magnetic-button] is its own instance. Add as many as you like; window.au.MagneticButton.refresh() picks up ones added later.

No. Load gsap before the script; nothing else is needed.

Related components.

Pro

Gooey Fan Menu

Click

Pro

Arrow Swap Button

Hover

Free

Rising Fill Button

Hover