How to Add Audio and Video to HTML

1. Adding Audio

You can use the <audio> tag to embed audio files in your HTML page:

<audio controls>
  <source src="audiofile.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

2. Adding Video

You can use the <video> tag to embed video files in your HTML page:

<video width="600" controls>
  <source src="videofile.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

3. Multiple Sources for Compatibility

Provide multiple formats for better browser support:

<audio controls>
  <source src="sound.ogg" type="audio/ogg">
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio>

<video width="600" controls>
  <source src="movie.webm" type="video/webm">
  <source src="movie.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

4. Optional Attributes

Example using optional attributes:

<video width="600" controls autoplay loop muted poster="thumbnail.jpg">
  <source src="video.mp4" type="video/mp4">
</video>