HTML <audio>
tag is used to play an audio file on a web page. At present there are three formats that are supported for HTML <audio>
tag. These are: mp3, wav and ogg.
In the below table, let’s see which browser supports the audio file format.
Browser | mp3 | wav | ogg |
---|---|---|---|
Chrome | Yes | Yes | Yes |
Edge | Yes | Yes | Yes |
Firefox | Yes | Yes | Yes |
Opera | No | Yes | Yes |
Safari | Yes | Yes | No |
<audio>
ElementIn an Example below I will write a code to show you how you can use the audio element.
Example
<!DOCTYPE html> <html> <head> <title>HTML Audio</title> </head> <body> <audio controls> <source src="#sound.ogg" type="audio/ogg"> <source src="#sound.mp3" type="audio/mpeg"> </audio> </body> </html>
Code Explanation
<audio>
element we have added two <source>
elements, this is because if the browser doesn’t support the first audio format, it will definitely support the second one. Related Posts