HTML Video Get Certified
What is the HTML Video Element?
The HTML <video> element allows you to embed video content directly into web pages. With HTML5, you can play videos without plugins, control playback with attributes like controls, autoplay, and muted, and support multiple formats for better browser compatibility.
Key Video Attributes
- controls – Shows play, pause, volume, and fullscreen buttons.
- autoplay – Starts playing the video automatically (usually requires
muted). - muted – Mutes the audio (needed for autoplay in most browsers).
- loop – Makes the video repeat continuously.
- poster – Displays an image before the video starts playing.
HTML Video Code Examples
1. Basic HTML Video Element
A simple video player with controls.
What this code does: Displays a video player using the <video> tag with an MP4 source and standard controls.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic HTML Video</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
video { max-width: 100%; background: #000; display: block; }
</style>
</head>
<body>
<h2>Basic HTML Video</h2>
<video width="640" height="360" controls>
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<p>This is a basic HTML5 video element with playback controls.</p>
</body>
</html>
2. Embedding a YouTube Video
Embed a YouTube video using an <iframe>.
What this code does: Shows how to embed a YouTube video player inside an HTML page.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>YouTube Embed</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
iframe { max-width: 100%; }
</style>
</head>
<body>
<h2>YouTube Video Embed</h2>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/ScMzIvxBSi4"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
<p>This example embeds a YouTube video using an iframe.</p>
</body>
</html>
3. Video with Autoplay (Muted)
Most browsers only allow autoplay when the video is muted.
What this code does: Starts playing the video automatically (muted) as soon as the page loads.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Autoplay Video</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
video { max-width: 100%; background: #000; display: block; }
</style>
</head>
<body>
<h2>Autoplay Video (Muted)</h2>
<video width="640" height="360" controls autoplay muted>
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<p>Note: Autoplay usually requires the muted attribute in modern browsers.</p>
</body>
</html>
4. Responsive HTML Video
Make the video scale properly on different screen sizes.
What this code does: Uses CSS so the video always fits the container width while keeping its aspect ratio.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Responsive Video</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
.video-container {
max-width: 640px;
}
video {
width: 100%;
height: auto;
display: block;
background: #000;
}
</style>
</head>
<body>
<h2>Responsive HTML Video</h2>
<div class="video-container">
<video controls>
<source src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/Sintel.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
<p>This video scales automatically to fit different screen sizes.</p>
</body>
</html>
Additional Tips
Always provide multiple <source> elements (MP4 + WebM) for better browser support. Use the poster attribute to show a thumbnail before the video plays. For accessibility, consider adding captions with the <track> element.
Web Resources on HTML Video
1. MDN : HTML video Element Reference
2. MDN : HTMLVideoElement API
3. HTML.com : HTML Video Tag Guide
Questions and Answers related to HTML Video
The <video> element embeds video content in a webpage. Use the controls attribute for playback controls and one or more <source> tags to specify video files in different formats (MP4, WebM, etc.).
Add the autoplay attribute. Most modern browsers also require the muted attribute for autoplay to work. Example: <video controls autoplay muted>...</video>.
Use an <iframe> with the YouTube embed URL (found under Share → Embed on YouTube). Include allowfullscreen and appropriate allow attributes for the best experience.
Set the video’s CSS to width: 100% and height: auto, or wrap it in a container that maintains the aspect ratio. This ensures the video scales properly on different screen sizes.
With the <video> tag you host the file yourself and have full control. YouTube embeds are easier (no hosting or bandwidth concerns) but rely on YouTube’s player and policies.
MP4 (H.264) is the most widely supported format. For better coverage you can also provide a WebM version as a second <source>.
🧪 Test Your HTML Code
Edit the HTML code on the left and click “Run Code” to see the result on the right.
Click “Run Code” to see the result here.