Introduction
The <video>
element in HTML is used to embed video content into a web page. It provides a standard way to embed video files directly into HTML documents, allowing users to view the video content without the need for additional plugins.
Here’s a basic example of how you might use the <video>
element:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Example</title>
</head>
<body>
<video controls width="600" height="400">
<source src="cars.mp4" type="video/mp4">
</video>
</body>
</html>
Output:
In this example:
- The
<video>
element defines a video player. - The
controls
attribute adds standard video controls (play, pause, volume control, etc.) to the player. - The
width
andheight
attributes specify the dimensions of the video player. - The
<source>
element provides the video source using thesrc
attribute, and thetype
attribute specifies the MIME type of the video file.
You can include multiple <source>
elements to provide different video formats (e.g., MP4, WebM, Ogg) to ensure compatibility across different browsers. The browser will choose the first supported video format from the provided <source>
elements.