04.21 · Micro-Interactions

Error Shake

A field shakes side to side when the input is wrong. Best for sign-in forms.

Click it

Sign in with a wrong or empty password (the right one is letmein), or press Show me.

Sign in

Try it

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

Shake distance

How far the field swings left and right.

Number of swings

Four to six swings read as a head shake.

Speed

How long the whole shake lasts.

Copy the prompt

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

Add an error shake to [the form field that can be rejected, such as a password]. When the value is wrong or missing, move the field quickly left and right a few times, each swing smaller than the last, and end exactly where it started, like a head shaking no. Turn its border red and show a short message saying what went wrong, because movement and color alone do not explain the problem. Move only its horizontal position so the shake stays smooth, and restart the shake on every failed try. If the visitor has reduced motion turned on, skip the shake and keep the red border and the message. 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

  • Sign-in forms
  • Codes and PINs
  • Form fields

Avoid on

  • Whole pages
  • Warnings