HTML Audio
Subject: html
π HTML <audio> Element
The <audio> element in HTML5 allows you to embed sound content β such as music, narration, or sound effects β directly into a web page without needing any plugins.
β
Why Use HTML <audio>?
- π§ Native audio playback in modern browsers
- πΉοΈ Built-in controls for play, pause, and volume
- πΌ Supports multiple file formats for compatibility
- βΏ Better accessibility and page performance
π§± Basic Syntax
π οΈ Common <audio> Attributes
controls: Displays browser default audio controlsautoplay: Starts playback automatically when the page loadsloop: Repeats the audio once it endsmuted: Starts the audio in a muted state (useful for autoplay)preload: Specifies if and how audio should preloadnone: Donβt preloadmetadata: Preload only meta infoauto: Let the browser decide (default)
π§ Example: Basic HTML5 Audio Player
- Multiple
<source>tags help ensure cross-browser compatibility. - The message inside
<audio>is displayed if the browser doesnβt support the element.
π Example: Autoplay, Loop, Muted
autoplay: Starts playback automatically (often requiresmuted)loop: Plays the audio on repeatmuted: Starts the audio silently
πΆ Supported Audio Formats
| Format | Extension | Browser Support |
|---|---|---|
| MP3 | .mp3 | β All modern browsers (Most used) |
| Ogg | .ogg | β Firefox, Chrome, Opera |
| WAV | .wav | β Modern browsers, larger file size |
π Note: MP3 is the most commonly supported and used format.
βΏ Accessibility Tips
- Always include
controlsfor user playback control. - Avoid autoplay with sound unless muted.
- Provide transcripts for essential audio content when possible.
π Key Takeaway
- HTML5
<audio>is the standard way to embed sound content on web pages. - Use multiple
<source>formats for better compatibility. - Apply attributes like
autoplay,loop, andmutedcarefully. - Keep user experience and accessibility in mind at all times.
Advertisement Slot 1
Advertisement Slot 2