A thumbs up that dips back, then flicks up with overshoot and floats a +1. The anticipation comes from a back-in-out cubic-bezier on one transition, so leaving is animated too.
Also known as: like button animation css, thumbs up hover, upvote icon animation.
<button class="hfx-thumbs-up-pop" aria-label="Like"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 10v12"/><path d="M15 5.9 14 10h5.8a2 2 0 0 1 1.9 2.6l-2.3 8a2 2 0 0 1-1.9 1.4H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.8a2 2 0 0 0 1.8-1.1L12 2a3.1 3.1 0 0 1 3 3.9Z"/></svg><span class="hfx-thumbs-up-pop-plus" aria-hidden="true">+1</span></button>
.hfx-thumbs-up-pop {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 3.5em;
height: 3.5em;
padding: 0;
border: 0;
border-radius: 50%;
background: color-mix(in srgb, var(--c) 12%, transparent);
color: var(--c);
cursor: pointer;
transition: background-color 0.25s ease, color 0.25s ease;
}
.hfx-thumbs-up-pop svg {
width: 1.55em;
height: 1.55em;
transform-origin: 15% 85%;
transition: transform 0.55s cubic-bezier(0.6, -0.6, 0.3, 1.6);
}
.hfx-thumbs-up-pop-plus {
position: absolute;
top: -0.1em;
right: -0.6em;
color: var(--c);
font: 700 0.85em/1 system-ui, sans-serif;
opacity: 0;
pointer-events: none;
}
.hfx-thumbs-up-pop:is(:hover, :focus-visible) {
background: var(--c);
color: #fff;
}
.hfx-thumbs-up-pop:is(:hover, :focus-visible) svg { transform: rotate(-18deg) scale(1.12); }
.hfx-thumbs-up-pop:is(:hover, :focus-visible) .hfx-thumbs-up-pop-plus {
animation: hfx-thumbs-up-pop-float 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) 0.25s both;
}
@keyframes hfx-thumbs-up-pop-float {
0% { opacity: 0; transform: translateY(0.6em) scale(0.5); }
35% { opacity: 1; transform: translateY(-0.2em) scale(1.1); }
100% { opacity: 1; transform: translateY(-0.6em) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-thumbs-up-pop, .hfx-thumbs-up-pop *, .hfx-thumbs-up-pop::before, .hfx-thumbs-up-pop::after, .hfx-thumbs-up-pop *::before, .hfx-thumbs-up-pop *::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.