A chat button that floats up on hover, then keeps bobbing gently while the pointer stays. Two animations are chained on one element: a quick rise, then an endless alternating bob that starts after it.
Also known as: hvr-bob, bobbing button css, floating chat button hover.
<button class="hfx-bob"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20.5 11.5a8 8 0 0 1-11.8 7L3.5 20l1.5-4.6a8 8 0 1 1 15.5-3.9z"/></svg>Chat with us</button>
.hfx-bob {
--c: var(--hfx-color, #3b82f6);
display: inline-flex;
align-items: center;
gap: 0.5em;
padding: 0.7em 1.6em;
border-radius: 0.5em;
font: 600 var(--hfx-size, 16px) system-ui, sans-serif;
cursor: pointer;
border: 0;
background: var(--c);
color: #fff;
border-radius: 2em;
box-shadow: 0 0.4em 0.9em -0.4em color-mix(in srgb, var(--c) 70%, transparent);
transition: box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);}
.hfx-bob svg {
width: 1.15em;
height: 1.15em;
}
.hfx-bob:is(:hover, :focus-visible) {
box-shadow: 0 1em 1.4em -0.7em color-mix(in srgb, var(--c) 60%, transparent);
animation: hfx-bob-rise 0.3s ease-out forwards, hfx-bob-bob 1.5s ease-in-out 0.3s infinite alternate;
}
@keyframes hfx-bob-rise {
to { transform: translateY(-0.5em); }
}
@keyframes hfx-bob-bob {
from { transform: translateY(-0.5em); }
to { transform: translateY(-0.2em); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-bob, .hfx-bob *, .hfx-bob::before, .hfx-bob::after, .hfx-bob *::before, .hfx-bob *::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.