ClickStart logoHTML5 to the point

Inserting audio into a document

You can use the audio element to insert an audio file into a document.

Unfortunately, no audio format is natively supported by all of the major browsers. However, you can use the source element to specify alternate audio files. The browser can then select a format based on its media type or codec support.

When you use the source element, the audio element's src attribute should be omitted. Otherwise, the source element will be ignored.

Attribute

Description

autoplay

Starts loading the audio immediately when the page loads and plays the audio as soon as it's buffered.

controls

Adds playback controls.

loop

Replays the audio when it is finished playing.

preload

Starts loading the audio immediately on page load, but does not play the audio.

src

Specifies the URL of the audio file.

Screenshot

Code

<audio src="deutschlandlied.oga" type="audio/ogg" controls></audio>
or
<audio controls>
<source src="deutschlandlied.ogg" type="audio/ogg">
<source src="deutschlandlied.mp3" type="audio/mpeg">
</audio>

Example