The <video>
tag in HTML is used to embed video content directly on a webpage. It allows you to display videos without relying on third-party plugins such as Flash. The <video>
tag is supported in modern browsers and provides various options to control playback, such as play, pause, volume, and more.
You can use the <video>
tag when you want to embed video content into your website. This is especially useful for websites that require multimedia elements like tutorials, product demonstrations, entertainment content, or educational videos. It ensures that users can view videos without needing any external plugins.
The basic syntax of the <video>
tag includes specifying the source of the video file and adding controls for the user to interact with the video.
src
- Specifies the URL or path to the video file.controls
- Displays playback controls (play, pause, volume, etc.) for the user.autoplay
- Automatically starts playing the video when the page loads.loop
- Loops the video after it finishes playing.muted
- Mutes the video audio by default.poster
- Specifies an image to be shown before the video starts playing.<video src="video.mp4" controls></video>
<!DOCTYPE html> <html> <head> <title>Video Example</title> </head> <body> <h2>Sample Video</h2> <video src="sample-video.mp4" width="640" height="360" controls> Your browser does not support the video tag. </video> </body> </html>
Similar to audio, you can include multiple video formats to ensure compatibility across different browsers. For example, using both MP4 and WebM formats:
<video controls> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> Your browser does not support the video tag. </video>
The <video>
tag comes with several useful attributes:
src
- The path to the video file.controls
- Allows the user to control the playback (play, pause, volume, etc.).autoplay
- Starts the video as soon as the page loads.loop
- Loops the video continuously after it finishes.muted
- Mutes the video by default when loaded.poster
- Displays a placeholder image before the video starts.width
and height
- Define the size of the video element.preload
- Specifies how the video should be loaded when the page loads. It can be set to auto
, metadata
, or none
.controls
attribute so users can control playback.autoplay
, consider whether it might disrupt the user experience.poster
attribute to display a preview image of the video before it starts.The <video>
tag is a powerful HTML element for embedding video content into web pages. By using the right attributes and ensuring compatibility across browsers, you can create a seamless and engaging multimedia experience for your website visitors.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!