HTML Video Element (<video>):
The HTML <video> element is used to embed videos within a web page. Videos are powerful for conveying information, entertainment, or instructional content. Here's a detailed guide on the HTML video element:
- Basic Syntax:
- The <video> element is used to embed a video, and it includes the src attribute specifying the source (URL) of the video.
- Source (src) Attribute:
- The src attribute contains the URL or file path of the video. It can be a relative or absolute path.
- Controls Attribute:
- The controls attribute adds video controls, such as play, pause, and volume, allowing users to interact with the video.
- Width and Height Attributes:
- The width and height attributes can be used to specify the dimensions of the video player.
- Alternative Content:
- The content within the <video> element serves as alternative content, displayed if the browser does not support the video.
- Autoplay and Loop Attributes:
- The autoplay attribute automatically starts playing the video when the page loads, and the loop attribute makes the video repeat.
- Poster Attribute:
- The poster attribute specifies an image to be displayed before the video starts playing. It is useful for providing a preview.
<video src="video.mp4" controls></video>
<video src="video.mp4" controls "> </video>
Output:- <video controls width="640" height="360">
<source src="video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<video src="video.mp4" controls autoplay loop> </video>
<video src="video.mp4" controls poster="video-preview.jpg"> </video>
Example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML Video Example</title> </head> <body> <h4>Welcome to My Video Page</h4> <video src="sample-video.mp4" controls width="640" height="360"> Your browser does not support the video tag. </video> <p>This is an example of using the <code><video></code> element in HTML to embed a video. The video includes controls for playback.</p> </body> </html>
Output:-
Welcome to My Video Page
This is an example of using the <video>
element in HTML to embed a video. The video includes controls for playback.