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 includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


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.


                <script src=""></script>
<h3>HTML Audio elements 101 usages via Javascript with classic parameters and behaviors.</h3>

<audio id="myAudio" controls autoplay>
  <source src="" type="audio/ogg">
  Your browser does not support the audio element.

  <button id="btnProps" onclick="defineIt()">Audio properties</button>
  <button id="btnPlay" onclick="fadeIt()">Play with Fade-in Fade-out</button>
  <button id="btnSet" onclick="setIt();defineIt();" class="input">Change audio source</button>
  <input id="inputUrl"class="input" placeholder="enter audio file's url here"/>

<p>Parameters at click:
  <li>Duration: <span id="duration">x</span> sec.</li>
  <li>Volume: <span id="volume"></span> %.</li>
  <li>Filename: <span id="filename"></span>.</li>
  <li>Folder: <span id="folder"></span></li>

<p>Audio files to tests:

  var defineIt = function() {
    setTimeout(function() {                           // Delay to let dom update
      var audio = $('audio')[0];
      document.getElementById("volume").innerHTML  = audio.volume * 100;
      document.getElementById("filename").innerHTML= audio.src.split("/").pop();
      document.getElementById("folder").innerHTML  = audio.src.split("/").slice(0, -1).join("/")+"/";
      document.getElementById("duration").innerHTML= audio.duration.toFixed(2);
    }, 100);
  var fadeIt = function() {
    var audio = $('audio')[0];
    var durationAudio  = Math.floor(audio.duration*1000),
        durationFadeIn = 1000,
        durationFadeOut= 1000;
    console.log("durationAudio :",durationAudio)
    audio.volume = 0;                                 // Set inital volume to zero
    $('audio').stop(true, false).animate({volume: 1}, durationFadeIn);  // Fade in volume to 100%;
    setTimeout(function() {                           // Fade out volume to zero
      $('audio').stop(true, false).animate({volume: 0}, durationFadeOut);
    }, durationAudio - durationFadeOut);

 var setIt = function() {    
    var audio = $('audio');
    var inputEl = document.getElementById('inputUrl');
    audio[0].src = inputEl.value!==""? inputEl.value :"";


                button.input {
  border-radius: auto 0 0 auto;
input.input {
  border-radius: 0 auto auto 0;
  margin-left: -1em;
  color: #666;
body {margin-left: 1em;}
li {margin-left: 1em;}
input {
  background-color: #99EE99;
  border: 1px solid #888;
  padding: 6px 12px;
  border-radius: 2px;