Text drifts gently up and down, like it is floating on water. Slow and small: a few pixels over three seconds is plenty to make a hero heading feel alive.
Also known as: hover float animation, bobbing text, levitate.
<div class="txt-float">Weightless</div>
.txt-float {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: inline-block;
color: var(--c);
animation: txt-float-bob 3s ease-in-out infinite;}
@keyframes txt-float-bob {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-0.2em); }
}
@media (prefers-reduced-motion: reduce) {
.txt-float, .txt-float *, .txt-float::before, .txt-float::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--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.