What is HTML Audio?
HTML audio allows you to embed sound files like music or voice into web pages using the <audio> tag.
Basic Syntax
HTMLRead-only
1
Audio Attributes
| Attribute | Description |
|---|---|
| controls | Shows play/pause controls |
| autoplay | Starts audio automatically |
| loop | Repeats audio |
| muted | Starts audio muted |
| preload | Hints how audio should be loaded |
Supported Audio Formats
| Format | Type |
|---|---|
| MP3 | audio/mpeg |
| WAV | audio/wav |
| OGG | audio/ogg |
Multiple Source Example
HTMLRead-only
1
Autoplay and Loop Example
HTMLRead-only
1
Fallback Text
Fallback text is displayed if the browser does not support the audio element.
HTMLRead-only
1
Best Practices
- Provide multiple formats for compatibility
- Avoid autoplay (bad user experience)
- Use controls for user interaction
- Optimize audio file size
- Provide fallback text
Common Mistakes
- Using unsupported audio formats
- Forcing autoplay with sound
- Not including controls
- Large audio files causing slow loading
Conclusion
HTML audio makes it easy to add sound to web pages. Proper usage ensures compatibility, performance, and a better user experience.