HTML <audio> Tag
The <audio> is one of the HTML5 elements added to allow embedding audio files to a web page. Since not all browsers support all audio formats, the audio file is encoded using special codecs.
The <source> tag or the src attribute is used to indicate the variations of the same audio file. The path to an audio file can contain an absolute or relative URLs.
The <audio> tag comes in pairs; the content is written between the opening (<audio>) and the closing (</audio>) tags.
<audio> <source src="URL" > <source src="URL" > </audio>
<html> <head> <title>Title of the document</title> </head> <body> <audio controls> <source src="/build/audios/jingle_bells.ogg" type="audio/ogg"> <source src="/build/audios/audio.mp3" type="audio/mpeg"> </audio> <p>Click the play button</p> </body> </html>
The <audio> tag has attributes, that indicate the path to the audio file, the way how the audio file should be played, etc.controls autoplay, loop and muted attributes are used their values can be omitted. If the attribute is specified, then by default this function is considered to be enabled.
|autoplay||Plays the audio file automatically after loading the page.|
|controls||Displays the control panel (start button, scroll, volume control). If the controls attribute is missing, the audio file will not be displayed on the page.|
|loop||Repeats continuously the audio file from the beginning after its completion.|
|muted||Mutes the sound when the audio file is played.|
|preload||Defines what browser should do, if the attribute controls is not specified.|
|auto||Playback starts after the page is loaded.|
|metadata||Tells the browser to upload a small portion of the file to determine its main characteristics: (for example, file size).|
|none||Playback starts only after clicking the corresponding button.|
|src||URL||Specifies the path to the audio file.|