html5 video tag Complete Guide

Basically in this tutorial we are explaining all kind of thing about html5 video tag.
I came up with this idea and it works perfectly for me so i thought i share with you may be it will help of you.
So basically we want to get tour of the HTML5 video tag how to resize poster to the videos actual size. Here i am writing some examples of HTML5 video tag.

HTML5 video hide controls until hover

Here i am showing video player controls on mouse hover and hide on mouse leave see below example.

// HTML Code
<video width="100%" height="100%" id="VideoId">
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
jQuery('#VideoId').hover(function toggleControls() {
    this.setAttribute("controls", "controls");
});
jQuery('#VideoId').mouseout(function(){
    this.removeAttribute("controls")
});
</script>

How to add video thumbnail in html5 video tag

Yes here is a way to set thumbnail image on HTML5 video if you want to see some pictures before play then you should follow the below example and code.
Add poster=”videothumbnail.png” to the video tag.

<video width="100%" height="100%" poster="videothumbnail.png" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

How to set HTML5 video tag thumbnail with 100% width

You can use simply set preload=”none” attribute to make VIDEO background visible. And you can use background-size: cover below is a example.

// HTML Code
<video width="100%" height="100%" poster="videothumbnail.png" preload="none" id="VideoId" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
        <embed src="video.swf" width="470" height="255">
    </object>
</video>

// CSS Code
<style>
#VideoId {
    background: transparent url('videothumbnail.png') 50% 50% / cover no-repeat ;
}
</style>

Without adding controls how to play video of html5 video tag

Here i am showing example for how can we play video without adding controls attribute in video tag using couple of lines JavaScript code.

// HTML Code
<video width="470" height="255" poster="placeholder.png" onclick="this.play()" controls>
    <source src="video.mp4" type="video/mp4">
    <source src="video.ogg" type="video/ogg">
    <source src="video.webm" type="video/webm">
    <object data="video.mp4" width="470" height="255">
    <embed src="video.swf" width="470" height="255">
    </object>
</video>

// JavaScript Code
<script>
var VideoId = document.getElementById('VideoId');
function videoPausePlayHandler(e) {
    if (e.type == 'playing') {
        //add controls
        VideoId.setAttribute("controls","controls");
    } else if (e.type == 'pause') {
        //remove controls
        VideoId.removeAttribute("controls");
    }
}
//Add event listeners
VideoId.addEventListener('playing', videoPausePlayHandler, false);
VideoId.addEventListener('pause', videoPausePlayHandler, false);
</script>

IF YOU LIKE THIS TUTORIAL DON’T FORGET SHARE WITH YOUR FRIENDS!

Author: Mukesh Jakhar

This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.
I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution of problems which i already solved.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts: You may like

How To Create a Modal Popup With CSS and JavaScript

Get Latitude Longitude from Address

cookie policy popup

How to make a sticky sidebar on scroll

How to get the value of HTML tag using JS

JavaScript timer countdown days hours minutes seconds

JavaScript validation on image field

Getting The Screen Resolution Using JavaScript

How to create textbox in html dynamically using javascript

How to get multiple selected values of select box in php

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.