Letters somersault one after another on hover and land in the accent color. Each span flips a full turn on X with its own perspective(), so the word stays flat enough for any layout.
Also known as: flip letters on hover, rotating letters text, letter spin hover.
<div class="hfx-text-letter-flip" aria-label="Switch"><span style="--i: 0">S</span><span style="--i: 1">w</span><span style="--i: 2">i</span><span style="--i: 3">t</span><span style="--i: 4">c</span><span style="--i: 5">h</span></div>
.hfx-text-letter-flip {
--c: var(--hfx-color, #3b82f6);
font-size: calc(var(--hfx-size, 16px) * 2.5);
font-family: system-ui, sans-serif;
font-weight: 800;
line-height: 1.15;
cursor: default;
display: inline-flex;}
.hfx-text-letter-flip span {
display: block;
transform: perspective(2em) rotateX(0);
transition: transform 0.6s cubic-bezier(0.5, 0, 0.25, 1), color 0.3s ease;
transition-delay: calc(var(--i) * 0.06s), calc(var(--i) * 0.06s + 0.15s);
}
.hfx-text-letter-flip:hover span {
color: var(--c);
transform: perspective(2em) rotateX(360deg);
}
@media (prefers-reduced-motion: reduce) {
.hfx-text-letter-flip, .hfx-text-letter-flip *, .hfx-text-letter-flip::before, .hfx-text-letter-flip::after, .hfx-text-letter-flip *::before, .hfx-text-letter-flip *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.