Skip to main content

What does the <video> element do? How do you specify a video source in HTML?

The <video> element is used to embed video directly into a web page: without third-party players like YouTube or Flash. It allows you to play, stop, seek, and control video using the browser's own tools.


1. Simplest example

html
<video src="video.mp4" controls></video>

What it does:

  • src="video.mp4": the path to the video file;
  • controls: shows standard controls (play, pause, volume, progress bar).

Result: the browser embeds a video player that can be started right on the page.


To support different video formats (MP4, WebM, Ogg), nested <source> tags are used: the browser picks the right one on its own:

html
<video controls width="640" height="360" poster="preview.jpg"> <source src="movie.mp4" type="video/mp4"> <source src="movie.webm" type="video/webm"> <p>Your browser does not support video.</p> </video>

What's here:

  • <source>: the file's path and type (type helps the browser determine the format);
  • poster: a preview image shown before playback starts;
  • inside it, you can specify fallback text for when the browser does not support <video>.

3. Main attributes of <video>

AttributePurposeExample
srcPath to the video file (if <source> is not used)src="clip.mp4"
controlsShows the control panelcontrols
autoplayStarts the video automatically when the page loads (often blocked by the browser)autoplay
mutedMutes the sound by default (needed for autoplay)muted
loopLoops the videoloop
posterPlaceholder image shown before playback startsposter="preview.jpg"
preloadControls preloading (none, metadata, auto)preload="metadata"
width / heightThe video player's dimensionswidth="640"

4. preload behavior

ValueWhat it does
noneThe video does not load until the user clicks play
metadataOnly information (duration, cover) is loaded
autoThe video may load in advance (if the browser decides it is needed)

5. Example with full control

html
<video width="600" controls autoplay muted loop poster="thumb.jpg"> <source src="intro.mp4" type="video/mp4"> <source src="intro.webm" type="video/webm"> Your browser does not support video. </video>

Behavior:

  • starts automatically;
  • without sound (so the browser does not block autoplay);
  • loops continuously;
  • shows the thumb.jpg picture before starting.

6. Supported formats

FormatMIME typeSupport
.mp4video/mp4All browsers
.webmvideo/webmModern browsers
.ogvvideo/oggFirefox, Opera

Tip: for cross-browser support, specify several <source> tags.


Summary:

PropertyValue
Tag<video>
PurposePlay video right on the page
SourceVia src or nested <source> tags
Main attributescontrols, autoplay, muted, loop, poster
AdvantagesBuilt-in player, no third-party libraries, support for multiple formats

In simple terms: <video> is a built-in HTML video player. The source is specified via src or <source>, so the browser knows which file to play and in what format.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.