04.05 · Micro-Interactions

Magnetic Button

Leans toward the pointer, then springs home. Best for one main button.

Hover it

Move the pointer close to the button (touch near it on a phone, or Tab to it and use the arrow keys), or press Show me.

Try it

Change a setting, then try it again or press Show me.

Pull strength

Stronger pulls feel playful; gentle ones feel calm.

Reach

How close the pointer must come before it pulls.

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add a magnetic effect to [the one button you want to stand out]. When the pointer comes within reach, pull the button part of the way toward it, more strongly the closer it gets, and move its label a little further so the label seems to float above the button. When the pointer leaves, let the button spring back to its place. Move it only with transforms so the layout never shifts, and use it on one or two buttons at most. On touch screens, pull the button toward the finger while it touches and send it home when it lifts. If the visitor has reduced motion turned on, move it quickly and evenly instead of letting it glide. Match the settings listed below.

Replace the words in brackets with your own element. Your settings are added at the end.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Hero buttons
  • Portfolio sites
  • One key action

Avoid on

  • Forms
  • Rows of buttons