HTML Audio
An HTML audio element is used to define sounds such as music and other audio clips. Currently, there is three supported file format for HTML 5 audio tag.
- mp3
- wav
- ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight, and similar technologies are used to play multimedia items.
Web browser supports which audio file format.
HTML Audio Tag Example:
The code to play mp3 file using HTML audio tag.
<!DOCTYPE> <html> <body> <audio controls> <source src="koyal.mp3" type="audio/mpeg"> </audio> </body> </html>
OUTPUT:
play ogg file using HTML audio tag:
Example:
<!DOCTYPE> <html> <body> <audio controls> <source src="koyal.ogg" type="audio/ogg"> </body> </html>
OUTPUT:
Supporting Browsers:
Browser version that fully supports the <audio> element.
Attributes of HTML Audio Tag:
Controls – It provides the audio controls which are displayed with play or pause buttons.
autoplay – Start playing as soon as it is ready.
loop – The audio file will start over again, each time when it is completed
muted – Mute the audio output.
preload – Author view to upload the audio file when the page loads.
src – Source URL of the audio file.
Example:
<!DOCTYPE> <html> <body> <audio controls autoplay loop> <source src="koyal.mp3" type="audio/mpeg"></audio> </body> </html>
OUTPUT:
MIME Types for HTML Audio format:
Audio Format MIME Type
mp3 audio/mpeg
ogg audio/ogg
wav audio/wav