AI CSS Animations

Trampoline Bounce Text

The word drops onto a trampoline, sinks into the mat and gets thrown back up, forever. The mat is one pseudo-element: its bottom border curves into a sag as its height grows.

Also known as: bouncing word animation, jumping text on a line, boing text effect.

Boing!

HTML

<div class="txt-trampoline-text"><span class="txt-trampoline-text-word">Boing!</span></div>

CSS

.txt-trampoline-text {
  --c: var(--txt-color, #3b82f6);
  font-size: var(--txt-size, 32px);
  font-family: system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.2;
  position: relative;
  display: inline-block;
  padding: 1em 0.8em 0.45em;
  color: var(--c);}
/* the frame legs */
.txt-trampoline-text::before {
  content: "";
  position: absolute;
  left: 0.1em;
  right: 0.1em;
  top: 1.95em;
  height: 0.42em;
  border: 0.08em solid color-mix(in srgb, var(--c) 45%, transparent);
  border-top: 0;
  border-bottom: 0;
}
/* the mat */
.txt-trampoline-text::after {
  content: "";
  position: absolute;
  left: 0.1em;
  right: 0.1em;
  top: 1.95em;
  height: 0.02em;
  border-bottom: 0.09em solid color-mix(in srgb, var(--c) 85%, transparent);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  animation: txt-trampoline-text-mat 1.3s infinite;
}
.txt-trampoline-text-word {
  display: inline-block;
  transform-origin: 50% 100%;
  animation: txt-trampoline-text-jump 1.3s infinite;
}
@keyframes txt-trampoline-text-jump {
  0%, 100% { transform: translateY(0.2em) scale(1.12, 0.86); animation-timing-function: ease-in; }
  10% { transform: translateY(-0.2em) scale(0.92, 1.1); animation-timing-function: ease-out; }
  45% { transform: translateY(-0.95em) scale(1, 1); animation-timing-function: ease-in; }
  80% { transform: translateY(0) scale(0.94, 1.08); animation-timing-function: ease-out; }
}
@keyframes txt-trampoline-text-mat {
  0%, 100% { height: 0.34em; animation-timing-function: ease-in; }
  8%  { height: 0.02em; animation-timing-function: ease-out; }
  13% { height: 0.09em; animation-timing-function: ease-in-out; }
  18% { height: 0.02em; animation-timing-function: ease-in-out; }
  23% { height: 0.05em; animation-timing-function: ease-in-out; }
  28%, 80% { height: 0.02em; animation-timing-function: ease-out; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-trampoline-text, .txt-trampoline-text *, .txt-trampoline-text::before, .txt-trampoline-text::after, .txt-trampoline-text *::before, .txt-trampoline-text *::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