HTML5 – Audio and video

HTML5 introduced the <audio> and <video> elements to allow the embedding of audio and video content in web pages.

Here is an example of how to embed an audio file in HTML5:

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

In this example, the <audio> element includes the controls attribute to display the default audio player controls, and the <source> element is used to specify the source of the audio file. The type attribute is used to specify the MIME type of the audio file.

You can also use the autoplay, loop, and muted attributes to control the playback of the audio.

Here is an example of how to embed a video file in HTML5:

<code><video controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support the video element.
</video>
</code>

The <video> element works in a similar way to the <audio> element. You can use the poster attribute to specify an image to display before the video starts playing, and the height and width attributes to specify the size of the video player.

You can style the audio and video players using CSS, such as by changing the appearance of the controls or by adding a border or margin. You can also apply CSS classes or IDs to the audio and video elements to give them specific styles.