A round speaker button: click and the sound waves collapse back into the speaker one after the other while a slash draws across it. The slash is stroked twice, once in the button color to cut a gap.
Also known as: mute button animation css, sound toggle button, volume icon toggle.
<label class="btn-mute-unmute">
<input class="btn-mute-unmute-input" type="checkbox" aria-label="Mute">
<span class="btn-mute-unmute-face" aria-hidden="true">
<svg viewBox="0 0 24 24">
<path class="btn-mute-unmute-speaker" d="M3.5 9.5h3.2L11.5 5v14l-4.8-4.5H3.5z"/>
<path class="btn-mute-unmute-wave" d="M15 9a4 4 0 0 1 0 6"/>
<path class="btn-mute-unmute-wave" d="M17.8 6.2a8 8 0 0 1 0 11.6"/>
<path class="btn-mute-unmute-cut" d="M4 4l16 16"/>
<path class="btn-mute-unmute-slash" d="M4 4l16 16"/>
</svg>
</span>
</label>.btn-mute-unmute {
--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-mute-unmute-input {
position: absolute;
inset: 0;
z-index: 1;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
border-radius: 50%;
}
.btn-mute-unmute-face {
display: grid;
place-items: center;
width: 3.2em;
height: 3.2em;
border-radius: 50%;
background-color: var(--c);
color: #fff;
box-shadow: 0 0.4em 1em -0.4em var(--c);
transition: background-color 0.3s ease, transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.btn-mute-unmute-face svg {
width: 1.55em;
height: 1.55em;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
overflow: visible;
}
.btn-mute-unmute-speaker { fill: currentColor; }
.btn-mute-unmute-wave {
transform-box: fill-box;
transform-origin: 0 50%;
transition: transform 0.35s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.25s ease;
}
.btn-mute-unmute-wave:nth-child(3) { transition-delay: 0.08s; }
.btn-mute-unmute-cut,
.btn-mute-unmute-slash {
stroke-dasharray: 23;
stroke-dashoffset: 23;
transition: stroke-dashoffset 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.btn-mute-unmute-cut {
stroke: var(--c);
stroke-width: 5;
transition-property: stroke-dashoffset, stroke;
}
.btn-mute-unmute:active .btn-mute-unmute-face { transform: scale(0.9); }
.btn-mute-unmute-input:focus-visible ~ .btn-mute-unmute-face {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face { background-color: color-mix(in srgb, var(--c) 55%, #334155); }
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face .btn-mute-unmute-cut { stroke: color-mix(in srgb, var(--c) 55%, #334155); }
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face .btn-mute-unmute-wave {
opacity: 0;
transform: translateX(-60%) scale(0.3);
transition-duration: 0.25s;
}
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face .btn-mute-unmute-wave:nth-child(2) { transition-delay: 0.08s; }
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face .btn-mute-unmute-wave:nth-child(3) { transition-delay: 0s; }
.btn-mute-unmute-input:checked ~ .btn-mute-unmute-face :is(.btn-mute-unmute-cut, .btn-mute-unmute-slash) {
stroke-dashoffset: 0;
transition-delay: 0.12s;
}
@media (prefers-reduced-motion: reduce) {
.btn-mute-unmute, .btn-mute-unmute *, .btn-mute-unmute::before, .btn-mute-unmute::after, .btn-mute-unmute *::before, .btn-mute-unmute *::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.