HTML5 introduced new element <audio>. This element specifies audio file on html document. By using this element user can listen audio file.HTML5 specifies a standard way to add audio file on web page with the help of audio element. <audio> element support three format of audio
- Ogg Vorbis : This format is supported by firefox3.5 or later, opera10.5 or later and google chrome 3.0 browser.
- MP3: This format will be supported by IE9, google chrome3.0 and safari3.0 or later.
- Wav: This format is supported by firefox3.5 or later, opera10.5 or later and safari 3.0 or later.
Syntax to use Audio element in html5
<audio src="source-file location" controls="controls">
Audio element properties
- src: In this attribute we have to pass the URL of the audio file.
- autoplay:This attribute specifies audio file is ready to play.
- loop: This attribute specifies audio file should replay or not.
- control: This attribute specifies to show control on page (play/pause/stop button).
- preload: This attribute specifies audio file should be preloaded or not.
Following example demonstrate use of audio element in html5
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<audio src="Video/Sleep Away.mp3" controls="controls"></audio>
Output of following code snippet is as follows