The <audio> element, new with HTML5, can be used to play music and other audio files in an HTML file/website.
<audio autoplay controls loop>
<source src="file-name.mp3" type="audio/mp3">
Any text inside this element will be shown on browsers that do not support this element...
</audio>
The audio formats supported (by most browsers, but at least by the element) are:
MP3 (audio/mpeg)The attributes for the audio element can be used in the opening audio tag to specify various playing options:
Control | Description |
---|---|
autoplay | Specify If Audio Should Play Automatically After Loading |
controls | Specify If Audio Controls Should Be Displayed |
loop | Specify If the Audio Should Start Over When Finished |
muted | Specify If Audio Should Be Muted by Default |
preload | Use auto, metadata, or none to Specify How the Audio Should be Pre-Loaded |
The <track> tag can be used to specify subtitles, captions, and other text files that should be displayed in conjunction with media while it plays.