HTML oncanplay Attribute

❮ HTML Attributes


//Accessing the element
var vid = document.getElementById("myVideo");

//Creating a function
vid.oncanplay = function() {
  alert("The video can start playing");


The canplay event run when the browser can start playing the audio/video.

Standard Syntax

<element oncanplay="script">

Browser Support


Applies to:

The oncanplay attribute can be used on the following element:

Element Attribute
<audio> oncanplay
<embed> oncanplay
<object> oncanplay
<video> oncanplay

Attribute Values

Value Description
script Specifies the script to be run on oncanplay.
❮ HTML Attributes