The `<audio>` and `<video>` elements in HTML allow you to embed audio and video content in your web page.
<audio> tag:
Here's an example of how you can use the `<audio>` element to embed an audio file in an HTML page:
<audio controls>
<source src="song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
The `controls` attribute adds controls to the audio player, such as a play/pause button and a volume slider. The `<source>` element specifies the source of the audio file, and the `type` attribute specifies the MIME type of the audio file. The text between the `<audio>` tags is displayed in browsers that do not support the `<audio>` element.
<video> tag:
Here's an example of how you can use the `<video>` element to embed a video file in an HTML page:
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video element.
</video>
The `width` and `height` attributes specify the dimensions of the video player, and the controls attribute adds `controls` to the player, such as a play/pause button and a volume slider. The `<source>` element specifies the source of the video file, and the `type` attribute specifies the MIME type of the video file. The text between the `<video>` tags is displayed in browsers that do not support the `<video>` element.
You can also use the `<audio>` and `<video>` elements to stream audio and video content from external sources, such as a streaming service or a server. To do this, you can use the `src` attribute to specify the URL of the audio or video file, like this:
<audio controls src="http://example.com/song.mp3"></audio>
<video width="320" height="240" controls src="http://example.com/movie.mp4"></video>
For more information about the `<audio>` and `<video>` elements, including a list of supported audio and video formats, you can refer to the HTML5 specification.
Comments (0)