A round media button whose play triangle splits into the two bars of pause, and back. Each half is a clip-path polygon with the same four points, so the shapes tween. Sound rings pulse while playing.
Also known as: play button animation css, play pause toggle css, media play button.
<label class="btn-play-pause">
<input class="btn-play-pause-input" type="checkbox" aria-label="Play">
<span class="btn-play-pause-face" aria-hidden="true">
<span class="btn-play-pause-icon"><i></i><i></i></span>
</span>
</label>.btn-play-pause {
--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;
isolation: isolate;}
.btn-play-pause-input {
position: absolute;
inset: 0;
z-index: 1;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
border-radius: 50%;
}
.btn-play-pause-face {
position: relative;
display: grid;
place-items: center;
width: 3.4em;
height: 3.4em;
border-radius: 50%;
background: var(--c);
color: #fff;
box-shadow: 0 0.4em 1em -0.4em var(--c);
transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.btn-play-pause-face::before,
.btn-play-pause-face::after {
content: "";
position: absolute;
inset: 0;
z-index: -1;
border-radius: 50%;
background: var(--c);
opacity: 0;
}
.btn-play-pause-icon {
display: flex;
width: 1.15em;
height: 1.3em;
transform: translateX(0.12em);
transition: transform 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.btn-play-pause-icon i {
flex: 1;
background: currentColor;
transition: clip-path 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.btn-play-pause-icon i:first-child { clip-path: polygon(0 0, 100% 25%, 100% 75%, 0 100%); }
.btn-play-pause-icon i:last-child { clip-path: polygon(0 25%, 100% 50%, 100% 50%, 0 75%); }
.btn-play-pause:active .btn-play-pause-face { transform: scale(0.92); }
.btn-play-pause-input:focus-visible ~ .btn-play-pause-face {
outline: 2px solid var(--c);
outline-offset: 0.2em;
}
.btn-play-pause-input:checked ~ .btn-play-pause-face .btn-play-pause-icon { transform: none; }
.btn-play-pause-input:checked ~ .btn-play-pause-face .btn-play-pause-icon i:first-child { clip-path: polygon(0 0, 68% 0, 68% 100%, 0 100%); }
.btn-play-pause-input:checked ~ .btn-play-pause-face .btn-play-pause-icon i:last-child { clip-path: polygon(32% 0, 100% 0, 100% 100%, 32% 100%); }
.btn-play-pause-input:checked ~ .btn-play-pause-face::before,
.btn-play-pause-input:checked ~ .btn-play-pause-face::after {
animation: btn-play-pause-wave 2s cubic-bezier(0.2, 0.6, 0.4, 1) infinite;
}
.btn-play-pause-input:checked ~ .btn-play-pause-face::after { animation-delay: 1s; }
@keyframes btn-play-pause-wave {
0% { opacity: 0.45; transform: scale(1); }
100% { opacity: 0; transform: scale(1.7); }
}
@media (prefers-reduced-motion: reduce) {
.btn-play-pause, .btn-play-pause *, .btn-play-pause::before, .btn-play-pause::after, .btn-play-pause *::before, .btn-play-pause *::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.