AI CSS Animations

Wiggle Icon

An icon button that wiggles like a ringing bell when hovered. The animation only runs during hover, so it never distracts while idle.

Also known as: shake icon hover, bell ring animation.

HTML

<button class="hfx-icon-wiggle" aria-label="Notifications">
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg>
</button>

CSS

.hfx-icon-wiggle {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  display: grid;
  place-items: center;
  width: 2.75em;
  height: 2.75em;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  color: var(--c);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.hfx-icon-wiggle svg {
  width: 1.4em;
  height: 1.4em;
  transform-origin: 50% 0;
}
.hfx-icon-wiggle:hover { background: color-mix(in srgb, var(--c) 20%, transparent); }
.hfx-icon-wiggle:hover svg { animation: hfx-icon-wiggle-ring 0.7s ease-in-out; }
@keyframes hfx-icon-wiggle-ring {
  0%, 100% { transform: rotate(0); }
  20%      { transform: rotate(14deg); }
  40%      { transform: rotate(-12deg); }
  60%      { transform: rotate(8deg); }
  80%      { transform: rotate(-5deg); }
}

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

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • 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 hover effects