HTML Audio


To embed audio in a web page, use the HTML5 <audio> tag. Its attributes function in a similar way to the <video> tag's. Since not all browsers accept all audio formats, special codecs are used to encode the audio file. The.mp3 file format is recommended because it is the most commonly used audio format on the planet.



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>

<audio controls>
<source src="Into-Oblivion.ogg" type="audio/ogg">
<source src="Into-Oblivion.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

</body>
</html>

Live Demo!



Output:

How does this work?


In audio, the controls attribute adds controls such as play, pause, and volume. You may use the source> feature to define alternate audio files for the browser to choose from. The browser will use the first format it recognizes. Browsers can only view the text between the <audio> and </audio> tags if the audio> element is not supported.


Linking of Audio Files


Audio files can be linked by just using the file name in the href attribute of the anchor tag.


Here's an example:


<p><a href="Into-Oblivion.mp3" width="200px" height="50px"> Into Oblivion </a></p>

Live Demo!



Output: