A product-hunt style vote box: click and it fills, the arrow shoots out the top and returns from below, and the last digit rolls from 8 to 9. The digit is a two-row reel inside an overflow window.
Also known as: upvote button css, vote counter button, like counter animation css.
<label class="btn-upvote-counter">
<input class="btn-upvote-counter-input" type="checkbox" aria-label="Upvote">
<span class="btn-upvote-counter-face" aria-hidden="true">
<span class="btn-upvote-counter-arrow"><svg viewBox="0 0 24 24"><path d="M12 5l8 11H4z"/></svg></span>
<span class="btn-upvote-counter-count">12<span class="btn-upvote-counter-digit"><span class="btn-upvote-counter-reel"><span>8</span><span>9</span></span></span></span>
</span>
</label>.btn-upvote-counter {
--c: var(--btn-color, #3b82f6);
position: relative;
display: inline-grid;
place-items: center;
font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
cursor: pointer;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.btn-upvote-counter-input {
position: absolute;
inset: 0;
z-index: 1;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
}
.btn-upvote-counter-face {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.25em;
width: 3.6em;
height: 4.2em;
border-radius: 0.75em;
background-color: color-mix(in srgb, var(--c) 6%, transparent);
color: var(--c);
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent);
transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.btn-upvote-counter-arrow {
overflow: hidden;
width: 1.1em;
height: 1.1em;
}
.btn-upvote-counter-arrow svg {
display: block;
width: 100%;
height: 100%;
fill: currentColor;
}
.btn-upvote-counter-count {
display: flex;
font-variant-numeric: tabular-nums;
}
.btn-upvote-counter-digit {
overflow: hidden;
height: 1.1em;
}
.btn-upvote-counter-reel {
display: flex;
flex-direction: column;
transition: transform 0.45s cubic-bezier(0.3, 1.5, 0.5, 1) 0.1s;
}
.btn-upvote-counter:active .btn-upvote-counter-face { transform: scale(0.93); }
.btn-upvote-counter-input:focus-visible ~ .btn-upvote-counter-face {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
.btn-upvote-counter-input:checked ~ .btn-upvote-counter-face {
background-color: var(--c);
color: #fff;
box-shadow: inset 0 0 0 2px var(--c), 0 0.5em 1em -0.5em var(--c);
}
.btn-upvote-counter-input:checked ~ .btn-upvote-counter-face .btn-upvote-counter-reel { transform: translateY(-50%); }
.btn-upvote-counter-input:checked ~ .btn-upvote-counter-face .btn-upvote-counter-arrow svg {
animation: btn-upvote-counter-shoot 0.6s cubic-bezier(0.5, 0, 0.3, 1);
}
@keyframes btn-upvote-counter-shoot {
0% { transform: translateY(0); }
40% { transform: translateY(-110%); animation-timing-function: step-end; }
41% { transform: translateY(110%); animation-timing-function: cubic-bezier(0.2, 0.8, 0.3, 1.3); }
100% { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
.btn-upvote-counter, .btn-upvote-counter *, .btn-upvote-counter::before, .btn-upvote-counter::after, .btn-upvote-counter *::before, .btn-upvote-counter *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--btn-color on the element or a parent.
Currently previewing #3b82f6.--btn-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 18px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.