The <video> tag lets you show videos right on a webpage without extra tools.
Video tag basics in HTML
<video src="video.mp4" controls></video>
The src attribute points to the video file.
The controls attribute adds play, pause, and volume buttons automatically.
<video src="movie.mp4" controls></video>
<video src="clip.webm" autoplay muted loop></video>
<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>
This page shows a video with controls. It uses two video formats for better browser support. The video resizes nicely on different screen sizes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Video Tag Example</title> <style> body { font-family: Arial, sans-serif; padding: 1rem; background-color: #f0f0f0; display: flex; flex-direction: column; align-items: center; gap: 1rem; } video { max-width: 100%; height: auto; border: 2px solid #333; border-radius: 0.5rem; } </style> </head> <body> <h1>Watch this sample video</h1> <video controls> <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" type="video/webm"> <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4"> Sorry, your browser does not support the video tag. </video> </body> </html>
Always include multiple <source> tags with different video formats for best browser support.
Use the controls attribute to give users easy control over the video.
Make sure your video files are optimized for web to load quickly.
The <video> tag lets you embed videos directly on your webpage.
Use controls to add play and pause buttons automatically.
Provide multiple video formats inside <source> tags for better compatibility.
Practice
<video> tag in HTML?Solution
Step 1: Understand the role of the <video> tag
The <video> tag is designed to embed video content directly into HTML pages.Step 2: Compare with other options
Options A, B, and C relate to audio, images, and text styling, which are not the purpose of <video>.Final Answer:
To embed videos directly on a webpage -> Option AQuick Check:
<video> tag = embed videos [OK]
- Confusing <video> with <audio> tag
- Thinking <video> adds images
- Assuming <video> styles text
<video> tag?Solution
Step 1: Identify the correct attribute for controls
The correct attribute to add playback controls iscontrolswithout any extra letters.Step 2: Check each option's attribute spelling
<video src="movie.mp4" controls></video> usescontrolscorrectly; others have incorrect or non-existent attributes.Final Answer:
<video src="movie.mp4" controls></video> -> Option DQuick Check:
Usecontrolsattribute to add buttons [OK]
- Misspelling 'controls' as 'control' or 'playcontrols'
- Using non-existent attributes like 'play'
- Forgetting to close the video tag properly
<video controls> <source src="video.webm" type="video/webm"> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video>
Solution
Step 1: Understand multiple <source> tags in <video>
The browser tries each <source> in order and plays the first supported format.Step 2: Analyze the source order and browser support
If the browser supports WebM, it plays video.webm; otherwise, it falls back to video.mp4.Final Answer:
Play video.webm if supported, else video.mp4 -> Option CQuick Check:
Multiple sources = fallback to supported video [OK]
- Assuming both videos play at once
- Thinking only the last source is used
- Ignoring fallback text for unsupported browsers
<video src="movie.mp4" controls> <source src="movie.webm" type="video/webm"> </video>
Solution
Step 1: Understand usage of
When using multiplesrcand<source>tags<source>tags, thesrcattribute on<video>should be omitted to avoid conflicts.Step 2: Check other options for errors
controlsis spelled correctly,<source>tags do not require closing slashes in HTML5, and multiple sources are allowed.Final Answer:
Thesrcattribute should not be used with<source>tags inside<video>-> Option BQuick Check:
Use eithersrcor<source>, not both [OK]
- Using src on video with source tags
- Thinking <source> needs closing slash
- Believing controls attribute is misspelled
<video> tag to achieve this?Solution
Step 1: Identify required attributes for autoplay, loop, and mute
The attributesautoplay,loop, andmutedenable automatic play, repeating, and silent start respectively.Step 2: Check which option includes all three without extra controls
<video src="clip.mp4" autoplay loop muted></video> has all three attributes and no controls, matching the requirement exactly.Final Answer:
<video src="clip.mp4" autoplay loop muted></video> -> Option AQuick Check:
Use autoplay, loop, muted together for silent looping video [OK]
- Forgetting muted causes autoplay to block
- Adding controls when not needed
- Missing one of the required attributes
Ready to prove it?
Pass the test and this pattern moves unknown
