Creating a link to play a sound file in HTML

Updated: 09/15/2017 by Computer Hope

sound fileLinking to a sound file using a href allows a browser to open and play an audio file if the viewer of your web page has properly configured their Internet browser. You can also use the <embed> tag or the newer <audio> tag to insert a sound file directly into a web page.

Tip: When it comes to audio files, we recommend using the .MP3 file format because it is widely accepted, utilized by all browsers and operating systems.

<a href> tag

Example:

<a href="https://www.computerhope.com/jargon/m/example.mp3">Play sound file</a>

Result:

Play sound file

<audio> tag

For all modern browsers, you can utilize the <audio> tag to have a usable media player as part of the web page to allow the visitor to play, stop, pause, and even download an audio file.

Example:

<audio controls>
<source src="https://www.computerhope.com/jargon/m/example.mp3" />
</audio>

Result:

<embed> tag

An older method of including audio files is to use the <embed> tag. While this method certainly works, it is less efficient than those which were mentioned above. As such, we recommend using one of the solutions demonstrated above.

<embed src="https://www.computerhope.com/clouds.mid" align="baseline" border="0" width="145" height="60" autostart="false" loop="true">

Note: Using the embed tag method requires that the user has a browser with a plugin, such as QuickTime. For example, the example above requires a plugin that supports MIDI files.

Additional information