<button class="play-pause-button">
<i>P</i>
<i>l</i>
<i>a</i>
<i>y</i>
<i>use</i>
</button>
<!-- dribbble - twitter -->
<a class="dribbble" href="https://dribbble.com/shots/8826937-Play-Pause-Button" target="_blank"><img src="https://cdn.dribbble.com/assets/dribbble-ball-mark-2bd45f09c2fb58dbbfb44766d5d1d07c5a12972d602ef8b32204d28fa3dda554.svg" alt=""></a>
<a class="twitter" target="_blank" href="https://twitter.com/aaroniker_me"><svg xmlns="http://www.w3.org/2000/svg" width="72" height="72" viewBox="0 0 72 72"><path d="M67.812 16.141a26.246 26.246 0 0 1-7.519 2.06 13.134 13.134 0 0 0 5.756-7.244 26.127 26.127 0 0 1-8.313 3.176A13.075 13.075 0 0 0 48.182 10c-7.229 0-13.092 5.861-13.092 13.093 0 1.026.118 2.021.338 2.981-10.885-.548-20.528-5.757-26.987-13.679a13.048 13.048 0 0 0-1.771 6.581c0 4.542 2.312 8.551 5.824 10.898a13.048 13.048 0 0 1-5.93-1.638c-.002.055-.002.11-.002.162 0 6.345 4.513 11.638 10.504 12.84a13.177 13.177 0 0 1-3.449.457c-.846 0-1.667-.078-2.465-.231 1.667 5.2 6.499 8.986 12.23 9.09a26.276 26.276 0 0 1-16.26 5.606A26.21 26.21 0 0 1 4 55.976a37.036 37.036 0 0 0 20.067 5.882c24.083 0 37.251-19.949 37.251-37.249 0-.566-.014-1.134-.039-1.694a26.597 26.597 0 0 0 6.533-6.774z"></path></svg></a>
.play-pause-button {
--play: #6D58FF;
--play-shadow: #{rgba(#6D58FF, .24)};
--pause: #2B3044;
--pause-shadow: #{rgba(#2B3044, .24)};
--color: #fff;
--icon: var(--color);
margin: 0;
line-height: 20px;
font-size: 14px;
padding: 11px 12px 11px 36px;
border-radius: 22px;
border: none;
background: none;
outline: none;
cursor: pointer;
display: flex;
position: relative;
backface-visibility: hidden;
appearance: none;
tap-highlight-color: transparent;
transform: translateY(var(--y, 0)) translateZ(0);
color: var(--color);
box-shadow: 0 var(--shadow-y, 6px) var(--shadow-b, 16px) var(--shadow, var(--pause-shadow));
background: radial-gradient(circle, var(--play) 0%, var(--play) 50%, var(--pause) 50.5%, var(--pause) 100%);
background-size: 400% 400%;
background-position: 0% 0%;
transition: background .8s, box-shadow .3s, transform .3s;
&:hover {
--y: -1px;
--shadow-y: 8px;
--shadow-b: 20px;
}
&:active {
--y: 1px;
--shadow-y: 4px;
--shadow-b: 12px;
}
&:before,
&:after {
content: '';
background: var(--icon);
width: var(--width, 16px);
height: 12px;
position: absolute;
left: 18px;
top: 15px;
backface-visibility: hidden;
transform-origin: 50% 100%;
transform: translateX(var(--x, 0)) translateZ(0);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
transition: clip-path .6s ease;
}
&:after {
--width: 3px;
--x: 6px;
}
i {
display: block;
font-weight: bold;
font-style: normal;
backface-visibility: hidden;
opacity: var(--o, 1);
transform: translateX(var(--x, 0));
transition: transform .6s, opacity .6s;
&:nth-child(2) {
--o: 0;
--x: 0;
}
&:nth-child(3) {
--x: -50%;
}
&:nth-child(4) {
--o: 0;
}
&:last-child {
--x: -50%;
}
}
&.paused {
--shadow: var(--play-shadow);
animation: var(--name, background-paused) .8s ease forwards;
i {
&:first-child {
--x: 40%;
}
&:nth-child(2) {
--o: 1;
--x: 100%;
}
&:nth-child(3) {
--x: 50%;
}
&:nth-child(4) {
--o: 1;
--x: 50%;
}
&:last-child {
--x: 0;
--o: 0;
}
}
&:before {
clip-path: polygon(0 0, 11px 6px, 11px 6px, 0 12px);
clip-path: polygon(0 0, 11px 6px, 11px 6px, 0 12px);
transition-delay: .9s;
}
&:after {
animation: to-play .9s ease forwards;
}
&.playing {
--shadow: var(--pause-shadow);
--name: background-playing;
&:before {
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
transition-delay: 0s;
}
&:after {
animation: to-pause 1.3s ease forwards;
}
i {
&:first-child {
--x: 0;
}
&:nth-child(2) {
--o: 0;
--x: 0;
}
&:nth-child(3) {
--x: -50%;
--o: 1;
}
&:nth-child(4) {
--o: 0;
--x: 0;
}
&:last-child {
--x: -50%;
--o: 1;
}
}
}
}
}
@keyframes to-play {
15% {
transform: translateX(6px) scaleY(1.1);
}
30% {
transform: translateX(6px) scaleY(.9);
}
45% {
transform: translateX(6px) scaleY(1.15);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
transform-origin: 50% 100%;
}
60%,
100% {
clip-path: polygon(0 9px, 3px 9px, 3px 12px, 0 12px);
clip-path: polygon(0 9px, 3px 9px, 3px 12px, 0 12px);
transform-origin: 50% 10.5px;
}
60% {
transform: translateX(6px);
}
99% {
transform: translateX(0) rotate(-270deg);
}
100% {
transform: translateX(0) rotate(-270deg) scale(0);
}
}
@keyframes to-pause {
0%,
50% {
clip-path: polygon(0 9px, 3px 9px, 3px 12px, 0 12px);
clip-path: polygon(0 9px, 3px 9px, 3px 12px, 0 12px);
transform-origin: 50% 10.5px;
}
0%,
39% {
transform: translateX(0) rotate(-270deg) scale(0);
}
40% {
transform: translateX(0) rotate(-270deg);
}
50% {
transform: translateX(6px) rotate(0deg);
}
60%,
100% {
transform: translateX(6px);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
clip-path: polygon(0 0, 3px 0, 3px 12px, 0 12px);
transform-origin: 50% 100%;
}
70% {
transform: translateX(6px) scaleY(1.15);
}
80% {
transform: translateX(6px) scaleY(.9);
}
90% {
transform: translateX(6px) scaleY(1.05);
}
100% {
transform: translateX(6px);
}
}
@keyframes background-paused {
from {
background-position: 0 0;
}
to {
background-position: 50% 50%;
}
}
@keyframes background-playing {
from {
background-position: 50% 50%;
}
to {
background-position: 100% 100%;
}
}
html {
box-sizing: border-box;
font-smoothing: antialiased;
}
* {
box-sizing: inherit;
&:before,
&:after {
box-sizing: inherit;
}
}
// Center & dribbble
body {
min-height: 100vh;
display: flex;
font-family: 'Roboto', Arial;
justify-content: center;
align-items: center;
background: #ECEFFC;
.dribbble {
position: fixed;
display: block;
right: 20px;
bottom: 20px;
img {
display: block;
height: 28px;
}
}
.twitter {
position: fixed;
display: block;
right: 64px;
bottom: 14px;
svg {
width: 32px;
height: 32px;
fill: #1da1f2;
}
}
}
View Compiled
document.querySelectorAll('.play-pause-button').forEach(button => {
button.addEventListener('click', e => {
if(button.classList.contains('playing')) {
button.classList.remove('paused', 'playing');
button.classList.add('paused');
} else {
if(button.classList.contains('paused')) {
button.classList.add('playing');
}
}
if(!button.classList.contains('paused')) {
button.classList.add('paused');
}
});
});
This Pen doesn't use any external JavaScript resources.