April 28, 2015 1:35 pm

How to Make a Custom Video Player with JavaScript, Part 1

In this tutorial, we will be building a custom a custom video player with JavaScript. It will consist entirely of black and white controls. We will create an object that when initialized will add controls to all video tag containers with a particular class. You can then continue to improve it and re-factor it to better serve your needs and patch various bugs.

How to Make a Custom Video Player with JavaScript, Part I

The controls would look like this:

To keep it short, the control buttons would have fixed width and height so we must make our video tags to have a certain fixed width as well.

Browser Support

The HTML5’s <video> tag is supported in IE >= 9, Firefox and Chrome >= 31, Safari >= 7 and Opera >= 27. It has a pretty decent support with 91.77% of people worldwide being able to run <video> tags.

Making the Video Player

First, we style a general .control class which all buttons will have:

We give the buttons a little bit of breathing room, give them the fixed size of 60px and set the background. Now, we just have to change the background-image of each button except for the play button (which will inherit only from the .control class)

We add the images for the other buttons:

Notice that we change the margins a bit for the time button and remove the pointer cursor for the volume and time buttons since they will not be clickable (there will be a range input for them)

Then, we give a fixed width to the video, the wrapper for the whole page and set a utility class:

Next, we deal with the markup. We add each video in a container of its own.

We will create our Video Player to receive a parameter which stipulates what the class of the container of each video is. In this demo, we will be using a class of media-wrapper.


In the next and final part, we are going to build the JavaScript API that will allow us to interact with the added videos.

Author Ivan Dimov

Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter

Tutorial Categories: