Open In App

How does the <audio> Element work in HTML5?

Last Updated : 01 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

HTML5 introduces the <audio> element, providing native support for embedding audio content directly into web pages. This element offers a seamless and better way to include audio files without relying on third-party plugins.

Syntax

<audio>
<source src="sample.mp3" type="audio/mpeg">
</audio>

Supported Audio Formats

HTML5 <audio> supports various audio file formats, such as MP3, WAV, and Ogg. This compatibility ensures that your audio content can be played across different browsers and platforms.

Attributes for Customization

Attribute Description
autoplay Starts playing the audio automatically when the page loads.
loop Loops the audio playback, allowing it to repeat continuously.
preload Specifies whether the audio should be loaded when the page loads. Options include none, metadata, and auto.
controls Designates what controls to display with the audio player. If present, the audio player includes playback controls.
muted Designates that the audio file should be muted by default when loaded.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads