HTML <audio> tag

HTML <audio> tag: Definition

Before HTML5 arrived on the scene, there was no standard for playing audio files on a web page, Therefore, the only way to play audio files was to use a plug-in such as flash. Now, the HTML5 <audio> element specifies a standard way to embed audio in a web page. Moreover, playback may be controlled using JavaScript.

It may contain one or more audio sources, represented using the src attribute or the <source> element: the browser will choose the most suitable one. It can also be the destination for streamed media, using a MediaStream.

Audio tag example:

Result :

Note: The audio tag is not supported in Internet Explorer 8 and earlier versions.

Attribute Value Description
autoplay autoplay This Boolean attribute specifies that the audio will automatically start playing as soon as it can do so without stopping to finish loading the data.
controls controls If specified, the browsers will display controls to allow the user to control audio playback, such as play/pause, volume, etc.
loop loop This Boolean attribute specifies that the audio will automatically start over again, upon reaching the end.
muted muted This Boolean attribute specifies whether the audio will be initially silenced. The default value is false, meaning that the audio will be played.
preload auto
Provides a hint to the browser about whether to download of the audio itself or its metadata. The autoplay attribute can override this attribute, because if you want to automatically play a audio, the browser will obviously need to download it.
src URL Specifies the location of the audio file. Alternatively, you can use the preferred <source> tag as it allows for multiple options.