How to play audio?

If you don’t want to mess with HTML elements:

var audio = new Audio('audio_file.mp3');;

function play() {
  var audio = new Audio('');;
<button onclick="play()">Play Audio</button>

This uses the HTMLAudioElement interface, which plays audio the same way as the <audio> element.

If you need more functionality, I used the howler.js library and found it simple and useful.

<script src=""></script>
    var sound = new Howl({
      src: [''],
      volume: 0.5,
      onend: function () {

Leave a Comment