how to add video in html

how to add video in html

3 hours ago 4
Nature

To add a video in HTML, use the <video> element. Here is how you can do it:

html

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

Explanation:

  • The <video> tag embeds a video player on the webpage.
  • The width and height attributes set the size of the video player.
  • The controls attribute adds playback controls like play, pause, and volume.
  • Inside the <video> tag, use one or more <source> tags to specify video files in different formats (e.g., MP4, OGG) so the browser can pick the supported one.
  • The text inside the <video> tag (e.g., "Your browser does not support the video tag.") is fallback content shown if the browser doesn't support the video element.

Additional optional attributes:

  • autoplay to start playing the video automatically.
  • loop to repeat the video continuously.
  • muted to mute the video by default.

Example with autoplay, loop, and muted:

html

<video width="320" height="240" controls autoplay loop muted>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

If you want to embed a video hosted on YouTube, use an <iframe> tag with the YouTube embed URL:

html

<iframe width="420" height="315" src="https://www.youtube.com/embed/VIDEO_ID"></iframe>

Replace VIDEO_ID with the actual YouTube video ID

Read Entire Article