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.
Inside, the ring shows how far the pull reaches: the button leans part of the way toward the pointer, and its label a little further. Point near it, or press Show me.
Stays put: the button ignores the pointer, shown as a ghost. Leans toward you: point near it, or press Show me, and it is pulled toward the pointer.
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.
Your settings
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 GitHubWhat it is
The full explanation is in README.md.