AI CSS Animations

Play Pause Pill Button

A pill audio button whose play triangle morphs into pause while flat equalizer bars spring to life. The icon is one clip-path polygon with eight points that fold from a triangle into two bars.

Also known as: play pause button css, play pause morph animation, audio play button with equalizer, play button animation css.

HTML

<label class="btn-play-pause-pill">
  <input class="btn-play-pause-pill-input" type="checkbox" aria-label="Play preview">
  <span class="btn-play-pause-pill-face" aria-hidden="true">
    <span class="btn-play-pause-pill-disc"><span class="btn-play-pause-pill-icon"></span></span>
    <span class="btn-play-pause-pill-text"><span>Play preview</span><span>Now playing</span></span>
    <span class="btn-play-pause-pill-eq"><i></i><i></i><i></i><i></i></span>
  </span>
</label>

CSS

.btn-play-pause-pill {
  --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-play-pause-pill-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  border-radius: 2em;
}
.btn-play-pause-pill-face {
  display: inline-flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.35em 1.15em 0.35em 0.35em;
  border-radius: 2em;
  background: var(--c);
  color: #fff;
  box-shadow: inset 0 1px color-mix(in srgb, #fff 25%, transparent), 0 0.5em 1.2em -0.5em var(--c);
  transition: transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1), box-shadow 0.3s ease;
}
.btn-play-pause-pill-disc {
  display: grid;
  place-items: center;
  width: 2.1em;
  height: 2.1em;
  border-radius: 50%;
  background: #fff;
  color: var(--c);
  transition: transform 0.4s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-play-pause-pill-icon {
  width: 0.78em;
  height: 0.85em;
  background: currentColor;
  transform: translateX(0.08em);
  clip-path: polygon(0 0, 50% 25%, 50% 75%, 50% 75%, 50% 25%, 100% 50%, 100% 50%, 0 100%);
  transition: clip-path 0.35s cubic-bezier(0.65, 0, 0.35, 1), transform 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.btn-play-pause-pill-text {
  display: grid;
  white-space: nowrap;
}
.btn-play-pause-pill-text span {
  grid-area: 1 / 1;
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.btn-play-pause-pill-text span + span {
  opacity: 0;
  transform: translateY(0.5em);
}
.btn-play-pause-pill-eq {
  display: flex;
  align-items: center;
  gap: 0.14em;
  height: 1em;
}
.btn-play-pause-pill-eq i {
  width: 0.16em;
  height: 100%;
  border-radius: 0.1em;
  background: currentColor;
  opacity: 0.55;
  transform: scaleY(0.2);
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.btn-play-pause-pill:hover .btn-play-pause-pill-face {
  transform: translateY(-0.1em);
  box-shadow: inset 0 1px color-mix(in srgb, #fff 25%, transparent), 0 0.8em 1.6em -0.5em var(--c);
}
.btn-play-pause-pill:hover .btn-play-pause-pill-disc { transform: scale(1.06); }
.btn-play-pause-pill:active .btn-play-pause-pill-face { transform: scale(0.96); }
.btn-play-pause-pill-input:focus-visible ~ .btn-play-pause-pill-face {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-icon {
  transform: none;
  clip-path: polygon(0 0, 34% 0, 34% 100%, 66% 100%, 66% 0, 100% 0, 100% 100%, 0 100%);
}
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-text span:first-child {
  opacity: 0;
  transform: translateY(-0.5em);
}
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-text span + span {
  opacity: 1;
  transform: none;
}
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-eq i {
  opacity: 1;
  animation: btn-play-pause-pill-eq 0.9s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-eq i:nth-child(2) { animation-duration: 0.7s; animation-delay: -0.3s; }
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-eq i:nth-child(3) { animation-duration: 1.1s; animation-delay: -0.6s; }
.btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-eq i:nth-child(4) { animation-duration: 0.8s; animation-delay: -0.15s; }
@keyframes btn-play-pause-pill-eq {
  0%   { transform: scaleY(0.25); }
  100% { transform: scaleY(1); }
}
@media (prefers-reduced-motion: reduce) {
  .btn-play-pause-pill-input:checked ~ .btn-play-pause-pill-face .btn-play-pause-pill-eq i {
    animation: none;
    transform: scaleY(0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-play-pause-pill, .btn-play-pause-pill *, .btn-play-pause-pill::before, .btn-play-pause-pill::after, .btn-play-pause-pill *::before, .btn-play-pause-pill *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --btn-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --btn-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar buttons