
How to embed an MP4 video on a web page using the video HTML tag
Navigation
- Home ⟶ Programming Examples ⟶ HTML Examples ⟶ How to embed an MP4 video on a web page using the video HTML tag
To embed an MP4 video in a web page, you can use the special HTML video tag.
Here you can find an example of it:
<video width="100%" autoplay>
<source src="your-video-file.mp4" type="video/mp4">
</video>
So let's examine this code:
video: This is the HTML5 tag used to embed videos.
width and height: These attributes set the dimensions of the video player on the web page. You can adjust the values according to your needs.
In this example I have set the width to be 100% in order for the video to take the whole available space and didn't specify the height, in order that it's calculated dynamically to keep the video proportions.
If you prefer, you can also set a fixed height and width in pixels for the video.
autoplay: This attribute will make the video to play automatically, which is often required when adding it on a web page
source: This is a child tag of video and is used to specify the video source file. The src attribute should be set to the path of your MP4 video file. The type attribute specifies the MIME type of the video, in this case "video/mp4".
Discover more HTML Examples & Tutorials
HTML examples and tutorials
How to add a MP3 file to a web page and play music when user is loading it
How to embed an MP4 video on a web page using the video HTML tag
June 3,2023