Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div class="container">
  <div class="audio-player">
      <source src="" type="audio/mpeg">
    <div class="audio-player__content">
      <span class="title">Don’t Ever Forget</span>
      <span class="song-data">Arata Iiyoshi</span>
    <div class="audio-player__controls">
      <button aria-label="Play"><i class="material-icons">play_arrow</i></button>
      <button class="audio-player__time-display">0:00 / ?:??</button>


                @import url('|Roboto:300,300i,400,400i,500,500i');
html, body {
  background-color: #1e1e1e;
  color: #fafafa;
  font-size: 16px;
  font-family: "Roboto", Helvetica, Arial, sans-serif;
  font-weight: 300;
  line-height: 1.5;
  margin: 0;
  height: 100%;
  width: 100%;
*, *::before, *::after {
  box-sizing: border-box;
body {display: flex;}

.container {
  width: 100%;
  max-width: 640px;
  margin: auto;
  padding: 1rem;

$standard-curve: cubic-bezier(0.4, 0, 0.2, 1);

.audio-player {
  overflow: hidden;
  background-color: #fff;
  color: #000;
  padding: 8px;
  display: flex;
  flex-direction: row;
  align-items: center;
  .audio-player__content {
    flex: 1;
    padding: 0.5rem 1rem;
    color: #727272;
    transition: color 0.2s $standard-curve;
    border-left: 1px solid rgba(black, 0.13);
    &:hover {color: #212121;}
    * {margin: 0;}
  .audio-player__controls {
    order: -1;
    padding-right: 8px;
    display: flex;
    flex-direction: row;
    align-items: center;
    .audio-player__time-display {
      font-size: 12px;
      width: auto; border-radius: 4px;
      color: #424242;
      // transition: color 0.2s $standard-curve;
      cursor: default;
      &:active, &:hover, &:focus {color: #424242;}
    button {
      transition: color      0.2s $standard-curve,
                  opacity    0.2s $standard-curve,
                  background 0.2s $standard-curve;
      margin-right: 8px;
      font-family: inherit;
      background: 0; border: 0;
      height: 40px; width: 40px;
      outline: 0; border-radius: 50%;
      cursor: pointer;
      color: #000; opacity: 0.52;
      &:hover, &:focus {background-color: rgba(black, 0.13);}
      &:active {opacity: 1;}
      i.material-icons {position: relative; right: 0px; top: 2px;}

.title {
  display: block;
.song-data {
  display: block;
  font-size: 0.75em;


                formatTime = (timeInSec) ->
    hrs  = ~~(timeInSec / 3600)
    mins = ~~((timeInSec % 3600) / 60)
    secs = ~~(timeInSec % 60)
    ret  = ""

    if hrs > 0
        ret += hrs + ":" + (if mins < 10 then "0" else "")
    ret += mins + ":" + (if secs < 10 then "0" else "")
    ret += secs
    return ret

createPlayer = (box) ->
    player = box.querySelector 'audio'
    pp = box.querySelector 'button'
    timeDisplay = box.querySelector ".audio-player__time-display"

    updateTime = ->
        timeDisplay.setAttribute "aria-label", "#{formatTime player.currentTime} out of #{formatTime player.duration}"
        timeDisplay.textContent = "#{formatTime player.currentTime} / #{formatTime player.duration}"

    #! Set initial states
    box.dataset.playbackState = 'unstarted'

    #! Button listener
    pp.addEventListener 'click', ->
        if player.paused
            .catch ->
            pp.setAttribute "aria-label", "Playback not resumed. Click to play."

    #! Audio listeners
    player.addEventListener 'playing', ->
        box.dataset.playbackState = 'playing'
        pp.setAttribute "aria-label", "Playing. Click to Pause."
        pp.innerHTML = """
            <i class="material-icons">pause</i>
    player.addEventListener 'pause', ->
        box.dataset.playbackState = 'pause'
        pp.setAttribute "aria-label", "Paused. Click to Play."
        pp.innerHTML = """
            <i class="material-icons">play_arrow</i>
    player.addEventListener 'ended', ->
        box.dataset.playbackState = 'end'
        pp.setAttribute "aria-label", "Playback ended. Click to restart."
    player.addEventListener 'waiting', ->
        box.dataset.playbackState = "buffering"
        pp.setAttribute "aria-label", "Loading..."

    player.addEventListener "timeupdate", updateTime
    player.addEventListener "durationchange", updateTime

players = document.querySelectorAll '.audio-player'
createPlayer player for player in players