Odd and even letters bounce on opposite beats, so the word zigzags like it is dancing in place. It is Tailwind's bounce keyframe with a half-cycle delay on every second letter.
Also known as: dancing letters css, alternating bounce text, zigzag text animation.
<div class="txt-dancing-text" aria-label="Groovy"><span aria-hidden="true"><span style="--i: 0">G</span><span style="--i: 1">r</span><span style="--i: 2">o</span><span style="--i: 3">o</span><span style="--i: 4">v</span><span style="--i: 5">y</span></span></div>
.txt-dancing-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;
color: var(--c);}
.txt-dancing-text span span {
display: inline-block;
animation: txt-dancing-text-bounce 1s infinite;
}
.txt-dancing-text span span:nth-child(even) {
animation-delay: -0.5s;
}
@keyframes txt-dancing-text-bounce {
0%, 100% { transform: translateY(-25%); animation-timing-function: cubic-bezier(0.8, 0, 1, 1); }
50% { transform: translateY(0); animation-timing-function: cubic-bezier(0, 0, 0.2, 1); }
}
@media (prefers-reduced-motion: reduce) {
.txt-dancing-text, .txt-dancing-text *, .txt-dancing-text::before, .txt-dancing-text::after, .txt-dancing-text *::before, .txt-dancing-text *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<div class="text-4xl font-bold text-blue-500" aria-label="Groovy"> <span aria-hidden="true"><span class="inline-block animate-bounce">G</span><span class="inline-block animate-bounce [animation-delay:-0.5s]">r</span><span class="inline-block animate-bounce">o</span><span class="inline-block animate-bounce [animation-delay:-0.5s]">o</span><span class="inline-block animate-bounce">v</span><span class="inline-block animate-bounce [animation-delay:-0.5s]">y</span></span> </div>
--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.