Welcome to End Point’s blog

Ongoing observations by End Point people

Creating a video player with time markers - step by step


Today we will show you how to create a video player with time markers using JavaScript and HTML5 only. Libraries that we will use are proven to be stable enough for production projects. What we want to achieve? The final result is visible below:

To simplify (or to make it harder for some of you :)) this tutorial we won't use any package management tools. The demo is available on Github here:


We will need some libraries (all of these are free to use in commercial projects):

Step 1 - creating a project skeleton

Let's create a new folder for our project and call it video-with-markers. Inside let's create a new file called "index.html", three folders: "css", "js" and "var".

We also need to copy libraries files and put it into a proper directory:

Let's open the index.html file and fill it with some basic structure, that will include libraries files too.

<!doctype html>
  <meta charset="utf-8"/>
  <meta http-equiv="x-ua-compatible" content="ie=edge"/>
  <title>Video with markers</title>
  <meta name="description" content=""/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="css/video-js.min.css"/>
  <link rel="stylesheet" href="css/videojs.markers.min.css"/>
  <script src="js/jquery-2.0.3.min.js"></script>
  <script src="js/video.min.js"></script>
  <script src="js/videojs-markers.min.js"></script>

Step 2 - activating player and creating markers

TIP: all the further code should be put inside the body tag.

First, we need to create a video tag:


We need to set an element "id" attribute and both classes "video-js vjs-default-skin" to let player CSS apply. Other attributes are not required and are here just for demo purpose. "Data-setup" attribute is an attribute that configures multiple player options. More details can be found in the documentation here:

At this point after launching index.html in a browser we should see a video player like this:

The only thing left is initializing markers. We can do this by adding some JavaScript code under the video player element:

// load video object
 var video = videojs('example_video_1');

 //load markers
    markers: [
        {time: 9.5, text: "this"},
        {time: 16,  text: "is"},
        {time: 23.6,text: "so"},
        {time: 28,  text: "cool"}

In this part we load an object of the Video.js player to video variable and then load a list of markers. Each marker object includes time in seconds when it should be shown and marker text.

Now, markers should be visible like on my this image and markers text will be visible after pointing at it:

It needs some additional CSS styling to achieve a result like on the first image but it's not much work.

The end

Almost the end. There are many more Video.js plugins ready to use, for example:

  • videojs-HDtoggle - button which toggles between HD and non-HD source,
  • videojs-playlist - plays videos continuously or by selecting them,
  • videojs-watermark - displays a watermark on top of the video.

With not much effort most of video player functionalities can be finalized. There is always some tweaking, but at least you can have a base for creating your project. And remember, if you will find bugs, report it! And if you have implemented something cool, share it!

Thanks for reading.


pete mulder said...

This was easy, thanks :)

Now I want to combine markers and playlist functionality. Ideally, my markers would be stretched over the timeline of the total (time of) vids in playlist. If that's not doable (I failed badly in my attempts), would you be able to tell how I can dynamically update markers on the timeline. Pleases note that vids don't have the same length, so the timeline needs to be rerendered as welll. Any (!) help would be highly appreciated!


Peter Hankiewicz said...

Hi Pete,

It is surely possible to stretch markers over the timeline but it will require creating a new plugin to create ranges. You can try to using this one: and create multiple ranges and disable a slider also.

Updating markers is pretty easy:
markers: markerArray


pete mulder said...

Thank Peter,
I forked rangeslider-videojs and will have a look.
Will try to keep you posted of how I get one. I may nudge you when I get stick, but I promise not to overdo it - and try not to :)

Yippie-ki-yay said...

Hi Peter. About this plugin, I've been trying to insert pauses on the marks (including commmands in the "onMarkerReached" options, as explain by the author in the forum he post the plugin; but I don't make it work... do you mind to help?



Peter Hankiewicz said...

Hi Yippie-ki-yay,

take a look at this example, it works just fine here:

var video = videojs('example_video_1');

//load markers
markers: [
{time: 9.5, text: "this"},
{time: 150, text: "is"},
{time: 250,text: "so"},
{time: 370, text: "cool"}
onMarkerReached: function () {

Apurv Gandhwani said...

Hi. I got the markers in mt timeline. Now I want to have markers of different color, say few markers of red color and few markers of green color, on a single timeline. How can I achieve this. Please help, I have been struggling with this. I tried to pass two arrays in markers array [ [],[] ] . But it didn't work.

Peter Hankiewicz said...

Hi Apurv,

when creating markers try this:
markers: [
{time: 9.5, text: "this", class: "marker-red"},
{time: 16, text: "is", class: "marker-blue"},
{time: 23.6,text: "so", class: "marker-red"},
{time: 28, text: "cool", class: "marker-blue"}

Then, in your CSS file set:
.marker-red { background-color: red; }
.marker-blue { background-color: blue; }

Good luck!

Apurv Gandhwani said...

Thanks for the previous solution Peter. I am facing one more problem. I want to jump to markers whenever I click a button. For example, say I have three markers on my timeline and three ui button for each of the marker. When I click first button, I should get jumped to first marker and same for other two buttons.

Peter Hankiewicz said...

Hi Apurv,

you can get a list of markers with:

var markers = player.markers.getMarkers();

Then you need to find a DOM element for each of the markers like this:

// foreach markers
var markerDiv = videoWrapper.find(".vjs-marker[data-marker-key='" + marker.key +"']");
// end foreach

To jump to any marker you can use:;

Apurv Gandhwani said...

But how can I connect this thing with the buttons in another component of another parent ?

Peter Hankiewicz said...

If you have the first button: 'button onclick="jumpToMarker(0)"'.

Then you need to create a function called jumpToMarker and using this function find an appropriate marker using the logic from my previous comment.

Apurv Gandhwani said...

can I have functionality like this:
I have two different sets of markers array of json objects, Array A and Array B. Below the video player I have two buttons, Button A and Button B. Now by default I show markers array A on video time line. Now when I click button B markers should change on timeline to array B. Same for Button A - when I click it Array B show come as markers. and I want this not to affect the video i.e. player should not reload the video and start it from begining everytime I change markers by button.

Is it possible to achieve this.

Peter Hankiewicz said...

Yes Apurv, you can do it.

When one of these buttons is clicked use player.markers.removeAll() to clean a list of markers and then just reload the list with new objects.

Apurv Gandhwani said...

How will I reload the list?

Will it be something like this:


case "A":
player.markers.removeAll(); //to remove markers
player.markers({ //to add new markers
markerStyle: {},
markers: ArrayA,


case "B":
player.markers.removeAll(); //to remove markers
player.markers({ //to add new markers
markerStyle: {},
markers: ArrayB,


Peter Hankiewicz said...

Sorry for a late reply.

Try to use player.markers.add() instead of player.markers().

Apurv Gandhwani said...

Hello Peter. I have implemented the markers. I want to have markers such that they have custom width/length on the basis of start time and endtime I pass. How can I do it? There is this function in marker.js " function createMarkerDiv(marker, duration) " but I don't know whether to use this for it or nor? and if yes then How to use it?

Peter Hankiewicz said...

Hi Apurv,

I don't think it's possible. You would need to rewrite the markers library to achieve it.

Apurv Gandhwani said...

Okay I have an idea but I need your suggestion for it. Here is how I am doing it right now

I take the length of playing bar of videojs in px. Then I divide it by duration (in secconds) of the video. Let's call it "A". Then I do markerLength = (startTime-endTime)*A. And then I set this markerLength as width of marker in markers.js like this

"width": markerLength, "margin-left": -parseFloat(markerDiv.css("width")) / 2 + 'px',
"left": getPosition(marker) + '%',

Peter Hankiewicz said...

Looks promising, I can see at least one issue:

markerLength = (startTime-endTime)*A

should be

markerLength = (endTime-startTime)*A

dheerprashant jain said...

Sir how can I avoid writing {time:---} multiple times.I tried making a string of the same for multiple time entries but it shows error at the console like this :
Cannot create property 'key' on string '{time:2384},{time:2892},{time:722},{time:1084},{time:600},{time:2622},{time:2658},{time:2706},{time:2704},{time:2468},{time:984},{time:2150},{time:1816},{time:136},{time:956},{time:884},{time:620},{time:1868},{time:2744},{time:2866},{time:224},{time:1316},{time:1410},{time:1728},{time:1830},{time:2158},{time:2570},{time:3168},{time:2436},{time:3408},{time:1516},{time:1864},{time:1264},{time:668},{time:270},{time:2054},{time:1652},{time:3204},{time:1956},{time:1658},{time:1808},{time:458},{time:890},{time:3078},{time:3206},{time:2884},{time:548},{time:2002},{time:976},{time:152}"'

Peter Hankiewicz said...


could you post your code here? Or send a link to Github or Gist.

dheerprashant jain said...

Hi, Sir I solved that problem. Sir I am not good with css can you please help me build the progress bar as shown in your first page ??