Use of Audio on web pages using HTML5.

The <audio> tag is used to embed audio content into a web page. It has several attributes that allow for customization, such as src to specify the source of the audio file, controls to include player controls such as play, pause, and volume, and autoplay to start playing the audio file automatically when the page loads.


Here is an example of how to use the <audio> tag:


Code:-

<audio src=”audiofile.mp3″ controls autoplay></audio>

You can also add alternative audio formats using the <source> tag, like this:



Code:- 

<audio controls>

  <source src=”audiofile.ogg” type=”audio/ogg”>

  <source src=”audiofile.mp3″ type=”audio/mpeg”>

  Your browser does not support the audio element.

</audio>

In this example, the <source> tag provides two alternative formats for the audio file, in case the browser does not support one of them. The last line, “Your browser does not support the audio element,” is shown if the browser does not support any of the formats.


You can also add captions to your audio using the <track> tag, like this:



Code:- 


<audio controls>

  <source src=”audiofile.mp3″ type=”audio/mpeg”>

  <track kind=”captions” src=”captions.vtt” srclang=”en” label=”English”>

</audio>


In this example, the <track> tag provides a captions file in WebVTT format, with the language set to English.

Leave a Comment