There are two methods for inserting videos in HTML and CSS: using HTML5 video tags and embedding external videos.
1. HTML5 Video
To insert a video using HTML5 video tags, you need to follow these steps:
Step 1: Add the <video> element to your HTML markup.
html <video src="video.mp4" controls></video>
In the above example, the "src" attribute specifies the path to the video file, and the "controls" attribute adds playback controls (play, pause, volume, etc.) to the video player.
Step 2: Specify alternative video formats.
To ensure cross-browser compatibility, it is recommended to provide the video in multiple formats. You can achieve this by including multiple <source> elements within the <video> element, each with a different video format. Browsers will automatically select the appropriate format based on their capabilities.
html <video controls> <source src="video.mp4" type="video/mp4"> <source src="video.webm" type="video/webm"> <source src="video.ogv" type="video/ogg"> Your browser does not support the video tag. </video>
In the above example, the first supported video format will be used, and if none are supported, the fallback text "Your browser does not support the video tag" will be displayed.
2. Embedding External Videos:
In addition to hosting videos on your own server, you can also embed videos from external sources such as YouTube or Vimeo. This method allows you to leverage the video hosting and streaming capabilities of these platforms.
To embed an external video, you can use the <iframe> element and the embed code provided by the video hosting service. Here's an example using YouTube:
html <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen></iframe>
In the above example, replace "VIDEO_ID" with the unique identifier of the YouTube video you want to embed. You can customize the width and height attributes to fit your design requirements.
When embedding external videos, it's important to note that you are relying on the availability and performance of the external service. If the service goes down or the video is removed, it may affect the functionality of your website.
The two methods for inserting videos in HTML and CSS are using HTML5 video tags and embedding external videos. HTML5 video tags provide a native way to display videos directly in web pages, while embedding external videos allows you to leverage the hosting and streaming capabilities of external platforms.
Other recent questions and answers regarding Examination review:
- Why is responsive design important in web development, especially for videos?
- How can we make a video responsive in HTML and CSS?
- What are the advantages of embedding videos from online platforms like YouTube or Vimeo?
- How can we link to a video file in the root folder using the video tag?

