An outlined pill with a hand and a count: clap and the hand jolts, a ring of sparks flies out and the number rolls up one, while clapping again rolls it back. A hidden checkbox switches it all.
Also known as: clap button, medium clap button css, applause button with count, clap animation css.
<label class="btn-clap-counter">
<input class="btn-clap-counter-input" type="checkbox" aria-label="Clap for this story">
<span class="btn-clap-counter-face" aria-hidden="true">
<span class="btn-clap-counter-icon">
<svg viewBox="0 0 24 24"><path d="M18 11V6a2 2 0 0 0-4 0M14 10V4a2 2 0 0 0-4 0v2M10 10.5V6a2 2 0 0 0-4 0v8M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-6-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></svg>
<span class="btn-clap-counter-burst"><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i></span>
</span>
<span class="btn-clap-counter-count"><span class="btn-clap-counter-roll"><span>248</span><span>249</span></span></span>
</span>
</label>.btn-clap-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-clap-counter-input {
position: absolute;
inset: 0;
z-index: 1;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
border-radius: 2em;
}
.btn-clap-counter-face {
display: inline-flex;
align-items: center;
gap: 0.55em;
padding: 0.55em 1.1em 0.55em 0.8em;
border-radius: 2em;
box-shadow: inset 0 0 0 1.5px color-mix(in srgb, currentColor 18%, transparent);
transition: box-shadow 0.3s ease, background-color 0.3s ease, transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-clap-counter-icon {
position: relative;
display: grid;
place-items: center;
}
.btn-clap-counter-icon svg {
width: 1.35em;
height: 1.35em;
fill: none;
stroke: currentColor;
stroke-width: 1.8;
stroke-linecap: round;
stroke-linejoin: round;
transform-origin: 50% 90%;
transition: transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1), stroke 0.3s ease;
}
.btn-clap-counter-burst {
position: absolute;
inset: 50% auto auto 50%;
}
.btn-clap-counter-burst i {
--a: 0deg;
position: absolute;
width: 0.14em;
height: 0.38em;
margin: -0.19em 0 0 -0.07em;
border-radius: 0.1em;
background: var(--c);
opacity: 0;
}
.btn-clap-counter-burst i:nth-child(2) { --a: 45deg; }
.btn-clap-counter-burst i:nth-child(3) { --a: 90deg; }
.btn-clap-counter-burst i:nth-child(4) { --a: 135deg; }
.btn-clap-counter-burst i:nth-child(5) { --a: 180deg; }
.btn-clap-counter-burst i:nth-child(6) { --a: 225deg; }
.btn-clap-counter-burst i:nth-child(7) { --a: 270deg; }
.btn-clap-counter-burst i:nth-child(8) { --a: 315deg; }
.btn-clap-counter-count {
height: 1.1em;
overflow: hidden;
font-variant-numeric: tabular-nums;
}
.btn-clap-counter-roll {
display: grid;
transition: transform 0.45s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-clap-counter-roll span { line-height: 1.1em; }
.btn-clap-counter:hover .btn-clap-counter-face { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 55%, transparent); }
.btn-clap-counter:hover .btn-clap-counter-icon svg { transform: rotate(-10deg); }
.btn-clap-counter:active .btn-clap-counter-face { transform: scale(0.94); }
.btn-clap-counter-input:focus-visible ~ .btn-clap-counter-face {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
.btn-clap-counter-input:checked ~ .btn-clap-counter-face {
background-color: color-mix(in srgb, var(--c) 10%, transparent);
box-shadow: inset 0 0 0 1.5px var(--c);
color: var(--c);
}
.btn-clap-counter-input:checked ~ .btn-clap-counter-face .btn-clap-counter-icon svg {
animation: btn-clap-counter-jolt 0.5s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-clap-counter-input:checked ~ .btn-clap-counter-face .btn-clap-counter-burst i {
animation: btn-clap-counter-burst 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
}
.btn-clap-counter-input:checked ~ .btn-clap-counter-face .btn-clap-counter-roll { transform: translateY(-1.1em); }
@keyframes btn-clap-counter-jolt {
0% { transform: scale(1) rotate(0deg); }
35% { transform: scale(1.25) rotate(-18deg); }
100% { transform: scale(1) rotate(0deg); }
}
@keyframes btn-clap-counter-burst {
0% { opacity: 1; transform: rotate(var(--a)) translateY(-0.7em) scaleY(1); }
100% { opacity: 0; transform: rotate(var(--a)) translateY(-1.5em) scaleY(0.2); }
}
@media (prefers-reduced-motion: reduce) {
.btn-clap-counter-input:checked ~ .btn-clap-counter-face .btn-clap-counter-icon svg,
.btn-clap-counter-input:checked ~ .btn-clap-counter-face .btn-clap-counter-burst i { animation: none; }
}
@media (prefers-reduced-motion: reduce) {
.btn-clap-counter, .btn-clap-counter *, .btn-clap-counter::before, .btn-clap-counter::after, .btn-clap-counter *::before, .btn-clap-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.