HTML Media is used to play sound and video on a web page without extra software.
Examples:
- Music
- Videos
- Tutorials
- Movies
HTML Audio Tag
Basic Syntax
<audio controls>
<source src="song.mp3" type="audio/mpeg">
</audio>
Audio Tag Attributes
| Attribute | Use |
| controls | Play / Pause buttons |
| autoplay | Plays automatically |
| loop | Repeat audio |
| muted | Sound off |
Example
<audio controls autoplay loop>
<source src="music.mp3">
</audio>
HTML Video Tag
Basic Syntax
<video controls width="300">
<source src="video.mp4" type="video/mp4">
</video>
Video Tag Attributes
| Attribute | Use |
| controls | Video controls |
| autoplay | Autoplay |
| loop | Repeat |
| muted | No sound |
| width | Video width |
| height | Video height |
| poster | Thumbnail image |
Example
<video controls width="400" poster="thumb.jpg">
<source src="movie.mp4">
</video>
Audio vs Video
| Audio | Video |
| Sound only | Sound + visuals |
| Uses <audio> | Uses <video> |
Supported Formats
Audio
Video
Important Tips
- Always use controls
- Use muted with autoplay
- Use poster for better UI