A like pill with a count: the thumb winds back, flicks up and fills, and the number rolls from 41 to 42. The roll is two stacked numbers in a clipped window; swap in your own count on the server.
Also known as: thumbs up animation css, like counter checkbox, upvote checkbox css.
<label class="chk-thumbs-up-counter"> <input type="checkbox" aria-label="Like"> <span class="chk-thumbs-up-counter-bg"></span> <svg class="chk-thumbs-up-counter-thumb" viewBox="0 0 24 24" aria-hidden="true"><path d="M3.5 10.5H7v10H3.5zM7 10.5l3.6-7.1c.4-.8 1.3-1.2 2.1-.8 1 .5 1.5 1.6 1.3 2.7l-.6 3.2h5.1a2 2 0 0 1 2 2.4l-1.4 7.5a2.5 2.5 0 0 1-2.5 2.1H7z"/></svg> <span class="chk-thumbs-up-counter-count"><span>41</span><span aria-hidden="true">42</span></span> </label>
.chk-thumbs-up-counter {
--c: var(--chk-color, #3b82f6);
font-size: var(--chk-size, 24px);
position: relative;
display: inline-flex;
align-items: center;
gap: 0.6em;
line-height: 1.3;
cursor: pointer;
-webkit-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
gap: 0.45em;
padding: 0.45em 0.95em 0.45em 0.8em;}
.chk-thumbs-up-counter input {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.chk-thumbs-up-counter-bg {
position: absolute;
inset: 0;
border: 0.08em solid color-mix(in srgb, currentColor 22%, transparent);
border-radius: 2em;
transition: background-color 0.25s ease, border-color 0.25s ease;
}
.chk-thumbs-up-counter-thumb {
position: relative;
width: 1.3em;
height: 1.3em;
fill: transparent;
stroke: color-mix(in srgb, currentColor 75%, transparent);
stroke-width: 1.7;
stroke-linejoin: round;
transform-origin: 25% 85%;
transition: fill 0.2s ease, stroke 0.2s ease;
}
.chk-thumbs-up-counter-count {
position: relative;
display: flex;
flex-direction: column;
height: 1.3em;
overflow: hidden;
font-weight: 600;
font-variant-numeric: tabular-nums;
transition: color 0.25s ease;
}
.chk-thumbs-up-counter-count > span {
transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chk-thumbs-up-counter:hover .chk-thumbs-up-counter-bg {
border-color: var(--c);
}
.chk-thumbs-up-counter input:checked + .chk-thumbs-up-counter-bg {
background: color-mix(in srgb, var(--c) 12%, transparent);
border-color: var(--c);
}
.chk-thumbs-up-counter input:checked ~ .chk-thumbs-up-counter-thumb {
fill: var(--c);
stroke: var(--c);
animation: chk-thumbs-up-counter-flick 0.6s ease-out;
}
.chk-thumbs-up-counter input:checked ~ .chk-thumbs-up-counter-count {
color: var(--c);
}
.chk-thumbs-up-counter input:checked ~ .chk-thumbs-up-counter-count > span {
transform: translateY(-100%);
transition-delay: 0.15s;
}
.chk-thumbs-up-counter input:focus-visible + .chk-thumbs-up-counter-bg {
outline: 0.12em solid var(--c);
outline-offset: 0.18em;
}
@keyframes chk-thumbs-up-counter-flick {
0% { transform: rotate(0deg) translateY(0) scale(1); }
25% { transform: rotate(14deg) translateY(0.06em) scale(0.9); }
60% { transform: rotate(-22deg) translateY(-0.18em) scale(1.18); }
80% { transform: rotate(4deg) translateY(0) scale(0.98); }
100% { transform: rotate(0deg) translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.chk-thumbs-up-counter, .chk-thumbs-up-counter *, .chk-thumbs-up-counter::before, .chk-thumbs-up-counter::after, .chk-thumbs-up-counter *::before, .chk-thumbs-up-counter *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--chk-color on the element or a parent.
Currently previewing #3b82f6.--chk-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 24px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.