<audio>: The HTML Audio Element

1 Description

The HTML <audio> element is used to allow users to play and listen to an audio file without having to download it, the audio file can be played directly in the web browser.

The audio file that is played is controlled via one or more <source> elements that are children of the <audio> element. Each <source> element define a single audio file with the src attribute, and declares what type of audio file it is with the type attribute.

Different web browsers support different audio file types. Not all audio file types are supported by all web browsers. Web browsers will examine each audio file <source> sequentially and play the first file it is capable of playing.

2 Examples

<!DOCTYPE html>
<html>
    <head>
        <title>Example Page</title>
    </head>
    <body>
        <h1>Audio Example Page</h1>
        <audio>
            <source src="audio_file_1.mp3" type="audio/mpeg"/>
            <source src="audio_file_2.ogg" type="audio/ogg"/>
        </audio>
    </body>
</html>

This document was last updated: