
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <video> Tag
Introduction to <video> Tag
The HTML <video> tag is used to embed a video media player into a website. To ensure proper rendering, you should offer various video formats, as not all browsers support the same ones. The path of the video file is specifies within the <source> tag or the src attribute. If the browser does not support the video format, you can provide alternative text within the video tag, which will be displayed instead.
The three video formats supported by the <video> element are MP4/MPEG 4, WebM, and Ogg. Special programs, or codecs, are used for compressing and decompressing large video files. The CSS object-position property can be used to adjust the video's location within the element's frame. Use the object-fit property to modify the video's size to fit the frame.
Syntax
Following is the syntax of <video> tag−
<video src="..." controls></video>
Attributes
The HTML video tag supports Global and Event attributes. It also accepts some specific attributes, which are listed bellow.
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | Specifies that the video will play automatically. |
controls | controls | Specifies that the video controls are displayed. |
height | pixels | Specifies the height of the video player. |
loop | loop | Specifies that the video will restart automatically after it finishes. |
muted | muted | Specifies that the audio will be muted. |
poster | URL | Specifies the image displayed while the video is downloading. |
preload | auto metadata none |
Specifies what the author believes will provide the best user experience. |
src | URL | Specifies the URL of the video's file's path. |
width | pixels | Specifies the width of the video player. |
Example: Creating Video Player
Lets look at the following example, where we use the preload attribute set to "auto," which loads the entire video when the page loads. This HTML code creates a webpage with a centered video player, specifying its dimensions and controls, and preloading the video.
<!DOCTYPE html> <html> <body> <center> <video width="400" height="200" controls preload="auto"> <source src= "https://cdn.pixabay.com/vimeo/165221419/ipad-2988.mp4?width=640&hash=4816e81143efa7f31f1e8c86c5605f43fdfac941" type="video/mp4"> </video> </center> </body> </html>
Example: Control Elements
In the following example, we use the controls attribute to add features like play, pause and volume. This HTML code creates a webpage with a centered video player, specifying its dimensions and embedding a video.
<!DOCTYPE html> <html> <body> <center> <video width="420" height="250" controls> <source src= "https://cdn.pixabay.com/vimeo/497754241/laptop-61037.mp4?width=640&hash=d25d7f4b8afa862b3252bdaeaf157934ceb1bb72" type="video/mp4"> </video> </center> </body> </html>
Example: Autoplay Video
In the following example, we use the autoplay attribute to make the video start automatically. This HTML code creates a webpage with a centered video player, specifying its dimension and autoplaying the embedded video.
<!DOCTYPE html> <html> <body style="background-color:#ABEBC6"> <center> <video width="420" height="250" autoplay> <source src= "https://cdn.pixabay.com/vimeo/497754241/laptop-61037.mp4?width=640&hash=d25d7f4b8afa862b3252bdaeaf157934ceb1bb72" type="video/mp4"> </video> </center> </body> </html>
Example: Video Player With Play & Pause Button
Considering the following example, where we run the script and add events like play, pause, full screen, and minimize.
<!DOCTYPE html> <html> <body style="background-color:#EAFAF1"> <div style="text-align:center"> <button onclick="Pauseplay()">PLAY/PAUSE</button> <button onclick="BScreen()">BIG SCREEN</button> <button onclick="SScreen()">SMALL SCREEN</button> <br> <video id="tutorial" width="400"> <source src= "https://cdn.pixabay.com/vimeo/497754241/laptop-61037.mp4?width=640&hash=d25d7f4b8afa862b3252bdaeaf157934ceb1bb72" type="video/mp4"> </video> </div> <script> var testvideo = document.getElementById("tutorial"); function Pauseplay() { if (testvideo.paused) testvideo.play(); else testvideo.pause(); } function BScreen() { testvideo.width = 500; } function SScreen() { testvideo.width = 200; } </script> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
video | Yes 4.0 | Yes 9.0 | Yes 3.5 | Yes 3.1 | Yes 11.5 |