Back to CSS Play/Pause Buttons Progress Ring Light JS
Share
HTML
<button class="pp-prog" type="button" aria-pressed="false" aria-label="Play" data-pp data-pp-prog>
  <svg class="pp-prog-ring" viewBox="0 0 56 56" aria-hidden="true">
    <circle cx="28" cy="28" r="24" fill="none" stroke="rgba(255,255,255,0.06)" stroke-width="3" />
    <circle
      class="pp-prog-fill"
      cx="28"
      cy="28"
      r="24"
      fill="none"
      stroke="#fbbf24"
      stroke-width="3"
      stroke-linecap="round"
      pathLength="100"
      stroke-dasharray="100"
      stroke-dashoffset="100"
      transform="rotate(-90 28 28)"
    />
  </svg>
  <svg viewBox="0 0 24 24" width="18" height="18" class="pp-prog-icon-svg" aria-hidden="true">
    <path class="pp-prog-icon" d="M8 5 L8 19 L19 12 Z" fill="currentColor" />
  </svg>
</button>
CSS
.pp-prog {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  padding: 0;
  background: radial-gradient(circle at 30% 25%, #2a2519 0%, #15120c 100%);
  border-radius: 50%;
  color: #fbbf24;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow:
    0 6px 18px -4px rgba(251, 191, 36, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    transform 0.15s,
    box-shadow 0.25s;
}
.pp-prog:hover {
  transform: translateY(-1px);
  box-shadow:
    0 10px 26px -4px rgba(251, 191, 36, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.pp-prog:focus-visible {
  outline: 3px solid rgba(251, 191, 36, 0.5);
  outline-offset: 3px;
}
.pp-prog-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.pp-prog-fill {
  transition: stroke-dashoffset 0.25s linear;
}
.pp-prog-icon-svg {
  position: relative;
  z-index: 1;
}
.pp-prog-icon {
  transition: d 0.3s cubic-bezier(0.5, 0, 0.3, 1.2);
}
.pp-prog[aria-pressed="true"] .pp-prog-icon {
  d: path("M7 5 H10 V19 H7 Z M14 5 H17 V19 H14 Z");
}

/* ── Drop-in JS for real progress ──
const btn  = document.querySelector('.pp-prog');
const fill = btn.querySelector('.pp-prog-fill');
const audio = document.querySelector('audio');

audio.addEventListener('timeupdate', () => {
  const pct = (audio.currentTime / audio.duration) * 100 || 0;
  fill.style.strokeDashoffset = String(100 - pct);
});
*/
JS
// ── Drop this on every page where you render a play/pause button ──
// Toggles aria-pressed + aria-label on click. The CSS handles all visuals.
document.querySelectorAll('[data-pp]').forEach(function (btn) {
  btn.addEventListener('click', function () {
    var playing = btn.getAttribute('aria-pressed') === 'true';
    btn.setAttribute('aria-pressed', String(!playing));
    btn.setAttribute('aria-label', !playing ? 'Pause' : 'Play');
  });
});