How does the <audio> Element work in HTML5?
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. |