Loading lesson path
Concept visual
Start at both ends
<audio> element is used to play an audio file on a web page.
Formula
The HTML < audio > ElementTo play an audio file in HTML, use the <audio> element:
<audio controls>
Formula
< source src ="horse.ogg" type ="audio/ogg">
< source src ="horse.mp3" type ="audio/mpeg">Your browser does not support the audio element. </audio>
Formula
HTML Audio - How It WorksThe controls attribute adds audio controls, like play, pause, and volume.
<source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.
<audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.
Formula
HTML < audio > AutoplayTo start an audio file automatically, use the autoplay attribute:
<audio controls autoplay>
Formula
< source src ="horse.ogg" type ="audio/ogg">
< source src ="horse.mp3" type ="audio/mpeg">Your browser does not support the audio element. </audio>
Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed. Add muted after autoplay to let your audio file start playing automatically (but muted):
<audio controls autoplay muted>
Formula
< source src ="horse.ogg" type ="audio/ogg">
< source src ="horse.mp3" type ="audio/mpeg">Your browser does not support the audio element. </audio>
The numbers in the table specify the first browser version that fully supports the <audio> element.
<audio> 4.0 9.0 3.5 4.0 10.5
There are three supported audio formats: MP3, WAV, and OGG. The browser support for the different formats is:
YES* YES*
NO