Skip to main content

All Methods to Play Video in HTML (With Examples)

HTML provides many ways to play video on a webpage, from simple inline videos to YouTube embeds, autoplay, fullscreen mode, and more. In this post, we will explore every commonly used technique to play videos in HTML with clean code examples.


1. Basic Video Playback

This is the simplest way to display a video on a web page.

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

Important: The controls attribute lets users play/pause the video.


2. Video with Width and Height

<video src="video.mp4" width="640" height="360" controls></video>

3. Using <source> Tag for Multiple Formats

This ensures the browser chooses the best supported format.

<video controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  Your browser does not support HTML5 video.
</video>

4. Auto-Play Video

The video will start automatically when the page loads.

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

Note: Most browsers require muted when autoplaying.


5. Auto-Play + Muted (Best Compatibility)

<video src="video.mp4" autoplay muted controls></video>

6. Loop the Video

This will make the video restart automatically after finishing.

<video src="video.mp4" autoplay muted loop controls></video>

7. Show Thumbnail Before Playing (Using Poster)

<video src="video.mp4" controls poster="thumbnail.jpg"></video>

8. Playing a Video from a URL

You can load a video hosted on a server or CDN.

<video src="https://example.com/video.mp4" controls></video>

9. Playing a Local Video File

Just place the video file in the same folder as your HTML file:

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

10. Add Custom Text for Unsupported Browsers

<video controls>
  <source src="video.mp4" type="video/mp4">
  Your browser does not support HTML video.
</video>

11. Enable Fullscreen Button

This is automatically included when you add controls. No extra code needed:

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

12. Disable Download Option

Use controlsList="nodownload" (works in Chrome-based browsers).

<video src="video.mp4" controls controlsList="nodownload"></video>

13. Play YouTube Video Using <iframe>

This is the most common method.

<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
frameborder="0"
allow="autoplay; encrypted-media"
allowfullscreen>
</iframe>
Replace VIDEO_ID with the actual YouTube video code.

14. Autoplay YouTube Video

<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID?autoplay=1&mute=1"
frameborder="0"
allow="autoplay"
allowfullscreen>
</iframe>

15. Embed YouTube Playlist

<iframe width="560" height="315"
src="https://www.youtube.com/embed/videoseries?list=PLAYLIST_ID"
frameborder="0"
allow="autoplay"
allowfullscreen>
</iframe>

16. Play MP4, WebM, and OGG Together (Best Practice)

<video controls width="640">
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  <source src="video.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>

17. Add Subtitles (Using <track>)

<video controls>
  <source src="movie.mp4" type="video/mp4">
  <track src="subtitles.vtt" kind="subtitles" srclang="en" label="English">
</video>

18. Style Video with CSS

<style>
video{
  border-radius:10px;
  width:600px;
}
</style>

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

Final Summary

  • <video> is the main HTML tag for playing videos
  • controls adds play/pause buttons
  • autoplay, loop, muted change playback behavior
  • <source> allows multiple formats
  • YouTube videos are embedded using <iframe>

In the next post, we will create a complete HTML video player interface with play, pause, and fullscreen styling using CSS and JavaScript.

Comments

Popular posts from this blog

HTML Forms Tutorial HTML Forms Tutorial HTML Forms allow users to enter and submit data. They are used everywhere—login forms, signup forms, search boxes, feedback forms, etc. In this complete tutorial, you will learn all form elements with examples and demos. 1. What is an HTML Form? A form collects user input using different form elements like text fields, checkboxes, radio buttons, buttons, and more. <form> Form elements go here... </form> 2. Basic Form Structure <form action="#" method="post"> <input type="text" placeholder="Enter name"> <button>Submit</button> </form> Submit Attributes: action → URL where form data is sent method="POST" → Secure data sending method="GET" → Data shows in URL 3. Text Input Field <i...
📸 HTML Image Gallery Tutorial for Beginners Image galleries make your website more beautiful and professional. In this tutorial, you will learn how to create different types of image galleries using HTML and CSS. 📌 1. Simple HTML Image Gallery This is the most basic gallery layout. <div> <img src="image1.jpg" width="200"> <img src="image2.jpg" width="200"> <img src="image3.jpg" width="200"> </div> ✔ Explanation All images are inside a <div> Each image has the same width They appear in a row 📌 2. Responsive Image Gallery (CSS Grid) This gallery automatically adjusts on mobile and PC. <style> .gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; } .gallery img { width: 100%; border-radius: 10px; } </style> <div class="galle...
📝 HTML Notes App Tutorial for Beginners (Full Project) In this tutorial, you will learn how to build a fully functional Notes App using HTML, CSS, and JavaScript. This app works on all devices and saves notes even after refreshing the page! ✨ Features of This Notes App Add new notes Edit notes Delete notes Dark Mode Search notes Auto-save using LocalStorage No backend needed 📌 Step 1 — HTML Structure Copy Code Run Demo <div class="container"> <h1>Notes App</h1> <button id="toggleDark">🌙 Dark Mode</button> <input type="text" id="searchBox" placeholder="Search notes..."> <textarea id="noteInput" placeholder="Write your note here..."></textarea> <button id="addNote">Add Note</button> <div id="notesList"></div> ...
HTML Tags Tutorial – A Complete Beginner-Friendly Guide HTML tags are the basic building blocks of every webpage. Whether you want to create a simple webpage or a full website, understanding HTML tags is the first and most important step. In this post, we’ll explore what HTML tags are, how they work, why they matter, and the most commonly used tags with examples. Table of Contents What Are HTML Tags? How HTML Tags Work Types of HTML Tags Most Common HTML Tags Self-Closing Tags Nesting Tags Practical Examples Best Practices What Are HTML Tags? HTML tags are keywords enclosed in angle brackets < > that tell the browser how to display content. Tags create elements such as headings, paragraphs, images, links, lists, buttons, forms, and much more. Example of a simple tag: <p>This is a paragraph.</p> How HTML Tags Work Most HTML tags come in pairs: <opening-tag>...
HTML Images Tutorial HTML Images Tutorial The <img> tag is used to display images on a webpage. In this tutorial, you'll learn how to add images, resize them, add borders, captions, and more. 1. Basic Image Tag The simplest way to add an image is by using the src and alt attributes. <img src="image.jpg" alt="My Image"> Attributes: src → Image URL alt → Text shown if image fails to load 2. Image Size (width & height) You can resize an image using width or height . <img src="photo.jpg" width="300" height="200"> 3. Responsive Images Responsive images automatically adjust to device size. <img src="photo.jpg" style="width:100%;max-width:400px;"> 4. Add Border to Images <img src="file.jpg" style="border:3px solid #333;...