HTML5 Video and JavaScript

After an article about the audio, it’s time to write also about HTML5 Video.

Working with HTML5 Video

The <video> element of HTML5 specification allows the user to play videos in the browser without installing additional plug-ins.

Example of use:

<video controls>
 <source src="video.webm" type="video/webm">
 <source src="video.ogv" type="video/ogg">
 <source src="video.mp4" type="video/mp4">
 No video support.

As in the case of audio, we can add the controls attribute, to show the basic UI elements for video playback control.

For details about the parameters, and other basic information, please take a look on W3Schools:


Let’s consider yet another example, in which the video is played only when user puts the mouse cursor on it:

<video id="vid" onmouseover="" onmouseout="this.pause()"
  autobuffer="true" width="400px" height="300px">
  <source src="my.ogv" type='video/ogg; codecs="theora, vorbis"'>
  <source src="my.mp4" type='video/mp4; codecs="mp4a.40.2"'>

For source elements we set also the type and codes attributes.

Ready solutions

There is a lot of good, ready solutions, based on HTML Video and JavaScript. And if so, why not take advantage of them?

JW Player

Working with this player was a pleasure. Unfortunately free version is for non-commercial use only.



For those looking for something stronger — Popcorn.js. It’s the HTML5 Media Framework, provided by Mozilla:


Yet another video player, already mentioned in one of previous articles:


At the end — additional resources related with HTML5 Video:


Historically, enabling video playback on a website for as much as possible the number of users, was quite a complicated task. Today, with HTML5 video and libraries based on it, only few lines of code is enough.

Programmer is able to reach desired (and working) effect quickly, without strange workarounds.