Alexander Gabriel

Dec 22, 2020

3 min read

Adding Audio to a HTML Webpage

Audio can enhance a user’s experience by invoking a mystic quality to a horoscope-reading application. It can give a notion of nostalgia by playing a TV theme song or add silly and playful aspects to a webpage designed for children. Done incorrectly, however, can turn an impressive flare into a rude annoyance. Below I will overview the simple steps in adding an audio element to your HTML with some notes on styling and etiquette.

  1. Use an <audio> tag-

An audio tag works just fine for modern day audio on webpages. It is supported on most browsers except Internet Explorer 8 as of 2020. It can play .mp3 files on all browsers, .wav (Not on Internet Explorer) and .ogg (Not on Internet Explorer and Safari.) You can add multiple <source> tags inside the <audio> tag to list multiple file formats. Such is the case if you want to play a .ogg file but are using Internet Explorer so you want to add a backup .mp3 file.

<audio controls>
<source src="sound.ogg">
<source src="sound.mp3">

2. Attributes -

The audio tag has several attributes you can use to control the audio. The src attribute is the file where you are getting the audio from. Make sure to put the path URL there.

The controls attribute is used to display the audio player on your page.

It is not recommended to have an audio file play upon loading your page without the ability to for the user to pause or turn it down. Modern webpage development is veering away from this as the audio can be seen as an annoyance. You many also find your audio only plays upon load, sometimes. Which is not what you want. If the audio controls are there the user knows they can play it.

The loop attribute will keep the audio file playing over and over again.

For a complete list of all the audio attributes visit.

3. Styling -

As of now, styling for the audio player is extremely limited. The only CSS properties you can change are width, box-shadow, border-radius and transform. However, you can implement some more style changes on the player using -webkit-media-controls as a CSS selector.


Another option would be to not display the controls on the audio tag and create your own using javascript or js frameworks such as MediaElement.js to build custom looking audio players.

That is all you need to add audio to your HTML webpage. If you would like to dive a bit deeper please visit the links below.