How to create a link to play a sound file in HTML

Updated: 07/13/2023 by Computer Hope
sound file

With HTML (HyperText Markup Language), linking 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. Alternatively, use the <embed> tag or the newer <audio> tag to insert a sound file directly in a web page.

Tip

With audio files, we recommend using the .MP3 file format because of its wide acceptance on the Internet, and is utilized by all browsers and operating systems.

<a href> tag

Example code

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

Result

Play sound file

<audio> tag

The <audio> tag can create a media player as part of the web page. It allows the visitor to play, stop, pause, or download an audio file. The <audio> element is compatible with all modern web browsers.

Example code

<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">