Ben Borgers

How to play an audio file with JavaScript

January 30, 2021

Playing a sound with pure javascript is surprisingly easy. First, you need a URL to the audio file you want to play. We’ll use this one:

Now, all it takes is two lines of code to play that sound file:

const sound = new Audio("");;

Subscribe to my newsletter!

A weekly round-up of new blog posts and updates to projects I’m working on.