AI CSS Animations

Shake Text

A quick horizontal shake, the universal 'no' for a wrong password or invalid form field. Plays once here; in your app, add the class when validation fails.

Also known as: error shake, wrong password shake, vibrate text.

Incorrect password

HTML

<div class="txt-shake">Incorrect password</div>

CSS

.txt-shake {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  display: inline-block;
  color: #dc2626;
  font-weight: 600;
  animation: txt-shake-no 0.5s ease-in-out;}
@keyframes txt-shake-no {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-0.25em); }
  40%, 80% { transform: translateX(0.25em); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-shake, .txt-shake *, .txt-shake::before, .txt-shake::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar text animations