Nearby lessons

14 of 24

๐ŸŽฌ HTML <video> Element

๐Ÿ“Œ What is HTML Video?

The <video> element in HTML is used to embed video content. It supports various attributes like controls, autoplay, muted, and formats like MP4 and WebM for wide browser compatibility.

๐ŸŽฅ Basic Usage

The <video> tag allows you to display video files directly in your browser with optional built-in controls.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

โฏ๏ธ Autoplay Behavior

To autoplay a video, most browsers require it to be muted as well.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿ“ผ Supported Video Formats

AttributeDescription
MP4๐ŸŽฏ Most widely supported format across all major browsers
WebM๐ŸŒ Open format with good compression and performance
Ogg๐Ÿ•ฐ๏ธ Older format with limited support

โš™๏ธ Common Attributes

AttributeDescription
controlsShows video player controls (play, pause, volume)
autoplayStarts playing video automatically (usually with muted)
loopRepeats the video once it finishes
mutedStarts the video with no sound
posterImage to display before the video plays
preloadInstructs browser how to preload the video: auto, metadata, none

๐Ÿงช Video API (JavaScript)

  • Methods: play(), pause(), load()
  • Properties: currentTime, volume, duration
  • Events: play, pause, ended

โœ… Best Practices

  • โœ… Always include controls if no custom player is used
  • โœ… Use poster to show a thumbnail before playback
  • โœ… Provide multiple formats for better compatibility
  • โœ… Mute the video if using autoplay
  • โœ… Use <track> for subtitles and accessibility

๐Ÿ“ Poster Image Example

The poster attribute adds a preview image before the video starts playing.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

๐Ÿง  Test Your Knowledge

5 Questions

Progress: 0 / 5
Keep Going!HTML Youtube