Audio in html
The <audio> tag in HTML allows you to embed audio files (like MP3, WAV, OGG) into your webpage. Users can play, pause, and control the volume.
Basic Audio Example
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>Supported Audio Formats
| Format | Type Attribute | Browser Support |
|---|---|---|
| MP3 | audio/mpeg | ✅ Most Browsers |
| WAV | audio/wav | ⚠ Large File Size |
| OGG | audio/ogg | ⚠ Not supported in Safari |
<audio> Tag Attributes
| Attribute | Description | Example |
|---|---|---|
src | Specifies the audio file URL | <audio src="song.mp3"></audio> |
controls | Adds default play, pause, and volume buttons | <audio controls> |
autoplay | Plays audio automatically when the page loads | <audio autoplay> |
loop | Repeats the audio file continuously | <audio loop> |
muted | Starts the audio in a muted state | <audio muted> |
