Back to CSS Play/Pause Buttons Skip Hub Light JS
Share
HTML
<div class="pp-hub" role="group" aria-label="Media controls">
  <button class="pp-hub-side" type="button" aria-label="Previous track">
    <svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true">
      <path d="M6 5 H8 V19 H6 Z M8 12 L19 5 V19 Z" fill="currentColor" />
    </svg>
  </button>
  <button class="pp-hub-main" type="button" aria-pressed="false" aria-label="Play" data-pp>
    <svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true">
      <path class="pp-hub-icon" d="M8 5 L8 19 L19 12 Z" fill="currentColor" />
    </svg>
  </button>
  <button class="pp-hub-side" type="button" aria-label="Next track">
    <svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true">
      <path d="M16 5 H18 V19 H16 Z M5 5 L16 12 L5 19 Z" fill="currentColor" />
    </svg>
  </button>
</div>
CSS
.pp-hub {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: #15151d;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  box-shadow: 0 12px 28px -10px rgba(0, 0, 0, 0.6);
}
.pp-hub-side {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 0;
  padding: 0;
  border-radius: 50%;
  color: #94a3b8;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition:
    color 0.15s,
    background 0.15s,
    transform 0.12s;
}
.pp-hub-side:hover {
  color: #f0eeff;
  background: rgba(255, 255, 255, 0.06);
}
.pp-hub-side:active {
  transform: scale(0.92);
}
.pp-hub-main {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f43f5e, #fb7185);
  border: 0;
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    0 0 0 0 rgba(244, 63, 94, 0.5),
    0 8px 18px -6px rgba(244, 63, 94, 0.7);
  transition:
    box-shadow 0.25s,
    transform 0.15s;
}
.pp-hub-main:hover {
  transform: translateY(-1px);
}
.pp-hub-main:focus-visible {
  outline: 3px solid rgba(244, 63, 94, 0.45);
  outline-offset: 3px;
}
.pp-hub-main[aria-pressed="true"] {
  box-shadow:
    0 0 0 6px rgba(244, 63, 94, 0.18),
    0 8px 22px -6px rgba(244, 63, 94, 0.85);
}
.pp-hub-icon {
  transition: d 0.35s cubic-bezier(0.5, 0, 0.3, 1.2);
}
.pp-hub-main[aria-pressed="true"] .pp-hub-icon {
  d: path("M7 5 H10 V19 H7 Z M14 5 H17 V19 H14 Z");
}
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');
  });
});