AI CSS Animations

Head Nod

A 3D yes: the box tips its face down and back up twice, pivoting low like a head on a neck. Pair it with Head Shake for yes and no feedback. Uses rotateX inside perspective().

Also known as: nod animation css, yes nod animation, nodding effect.

Yes

HTML

<div class="kfa-head-nod">Yes</div>

CSS

.kfa-head-nod {
  --c: var(--kfa-color, #3b82f6);
  font-size: var(--kfa-size, 16px);
  display: grid;
  place-items: center;
  width: 5.5em;
  height: 5.5em;
  border-radius: 1em;
  background: var(--c);
  color: #fff;
  font-family: system-ui, sans-serif;
  font-weight: 700;
  box-shadow: 0 0.6em 1.4em -0.6em color-mix(in srgb, var(--c) 70%, transparent);
  transform-origin: 50% 85%;
  animation: kfa-head-nod-yes 1s ease-in-out both;
}
@keyframes kfa-head-nod-yes {
  0%, 86%, 100% { transform: perspective(14em) translateY(0) rotateX(0); }
  14% { transform: perspective(14em) translateY(0.22em) rotateX(-30deg); }
  32% { transform: perspective(14em) translateY(-0.06em) rotateX(8deg); }
  50% { transform: perspective(14em) translateY(0.16em) rotateX(-22deg); }
  68% { transform: perspective(14em) translateY(0) rotateX(4deg); }
}

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

Customizing this snippet

  • Color: set --kfa-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --kfa-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 keyframe animations