top of page
Writer's pictureThe Tech Platform

How to add Audio in HTML


The HTML <audio> is used to add the audio clips or file on web pages. The HTML DOM defines methods, properties and events for the audio element. This allow us to load, play, pause, duration and volume.


Browsers which support <audio> elements are:

  • Google Chrome

  • Safari

  • Opera

  • Microsoft Edge/Internet Explorer

  • Firefox


Below are the Attributes :

  1. controls: add controls like play, pause, volume

  2. <source>: specify alternative audio file

  3. <audio></audio>: The text between the tag will be displayed on the web page. But there are many browsers that do not support <audio> element.


Example:

<!DOCTYPE html>
<html>
<body>
<h2> Audio of little birds singing in trees</h2>
<audio controls>
  <source src="https://static.wixstatic.com/mp3/0f65e1_b8a728f8fade43948729d8f6b584faff.wav" type="audio/ogg">
  
</audio>

</body>
</html>

Output:





Autoplay

If you want to start an audio automatically , then use autoplay attribute

<audio controls autoplay>
	<Source sec= "..........." type="............">
</audio>


Muted

If you want to start an audio automatically but muted

<audio controls autoplay muted>
    <source src="........" type=" .......">
</audio>




Sofia Sondh

The Tech Platform


0 comments

ความคิดเห็น


bottom of page