An icon button shaped like a coin that hops, spins two and a half turns and lands on its back, trading a star for a check. Stacked discs give the rim real thickness when it turns edge on.
Also known as: 3d coin flip css, spinning badge hover, flip coin button.
<button class="hfx-coin-flip-icon" aria-label="Collect reward">
<span class="hfx-coin-flip-icon-hop">
<span class="hfx-coin-flip-icon-coin">
<span class="hfx-coin-flip-icon-rim" style="--z: -0.15em"></span>
<span class="hfx-coin-flip-icon-rim" style="--z: -0.075em"></span>
<span class="hfx-coin-flip-icon-rim" style="--z: 0em"></span>
<span class="hfx-coin-flip-icon-rim" style="--z: 0.075em"></span>
<span class="hfx-coin-flip-icon-rim" style="--z: 0.15em"></span>
<span class="hfx-coin-flip-icon-face"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2.5l2.9 6 6.6.9-4.8 4.6 1.2 6.5L12 17.4l-5.9 3.1 1.2-6.5-4.8-4.6 6.6-.9z"/></svg></span>
<span class="hfx-coin-flip-icon-face hfx-coin-flip-icon-back"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg></span>
</span>
</span>
</button>.hfx-coin-flip-icon {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 5.5em;
height: 7em;
padding: 0;
border: 0;
background: none;
color: #fff;
cursor: pointer;
perspective: 30em;
}
.hfx-coin-flip-icon::after {
content: "";
position: absolute;
bottom: 0.6em;
left: 50%;
width: 3.4em;
height: 0.5em;
margin-left: -1.7em;
border-radius: 50%;
background: color-mix(in srgb, var(--c) 35%, transparent);
filter: blur(0.15em);
}
.hfx-coin-flip-icon-hop {
display: block;
}
.hfx-coin-flip-icon-coin {
position: relative;
display: block;
width: 4em;
height: 4em;
transform-style: preserve-3d;
transition: transform 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.hfx-coin-flip-icon-rim,
.hfx-coin-flip-icon-face {
position: absolute;
inset: 0;
border-radius: 50%;
}
.hfx-coin-flip-icon-rim {
background: color-mix(in srgb, var(--c) 60%, #000);
transform: translateZ(var(--z));
}
.hfx-coin-flip-icon-face {
display: grid;
place-items: center;
background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 45%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 75%, #000));
box-shadow: inset 0 0 0 0.25em color-mix(in srgb, var(--c) 80%, #000), inset 0 0 0 0.36em color-mix(in srgb, var(--c) 55%, #fff);
backface-visibility: hidden;
transform: translateZ(0.2em);
}
.hfx-coin-flip-icon-back {
transform: rotateY(180deg) translateZ(0.2em);
}
.hfx-coin-flip-icon-face svg {
width: 1.8em;
height: 1.8em;
fill: currentColor;
}
.hfx-coin-flip-icon:is(:hover, :focus-visible) .hfx-coin-flip-icon-coin {
transform: rotateY(900deg);
}
.hfx-coin-flip-icon:is(:hover, :focus-visible) .hfx-coin-flip-icon-hop {
animation: hfx-coin-flip-icon-hop 1.1s cubic-bezier(0.3, 0, 0.3, 1);
}
.hfx-coin-flip-icon:is(:hover, :focus-visible)::after {
animation: hfx-coin-flip-icon-shadow 1.1s cubic-bezier(0.3, 0, 0.3, 1);
}
@keyframes hfx-coin-flip-icon-hop {
0%, 100% { transform: translateY(0); }
35% { transform: translateY(-1.4em); }
70% { transform: translateY(0); }
82% { transform: translateY(-0.25em); }
}
@keyframes hfx-coin-flip-icon-shadow {
0%, 100% { transform: scale(1); opacity: 1; }
35% { transform: scale(0.6); opacity: 0.5; }
70% { transform: scale(1); opacity: 1; }
82% { transform: scale(0.9); opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
.hfx-coin-flip-icon, .hfx-coin-flip-icon *, .hfx-coin-flip-icon::before, .hfx-coin-flip-icon::after, .hfx-coin-flip-icon *::before, .hfx-coin-flip-icon *::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.