This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



Loads and starts playback of a media resource.

Method of dom/HTMLMediaElementdom/HTMLMediaElement


Return Value

No return value


Play method example.

<!DOCTYPE html>
    <title>Simple Video Example</title>
         function hidecontrol(e) {
           // Set controls to true or false based on their current state
           var video = document.getElementById('video1');
           if (video.controls == true) {
             // Controls are binary, true if there, false if not
             e.innerHTML = "Show controls";
           } else {
             // Controls are binary, true if there, false if not
             video.setAttribute("controls", true);
             e.innerHTML = "Hide controls";

         function playVideo(e) {
           var video = document.getElementById('video1');      //video element
           //  Toggle between play and pause based on the paused property
           if (video.paused) {
             var input = document.getElementById('videoFile');   //text box
             if (input.value) {
               //  Only load a video file when the text field changes
               if (input.value != video.src) {
                 video.src = input.value;
               e.innerHTML = "Pause";
           } else {
             e.innerHTML = "Play";

<video id="video1" controls >HTML5 video is not supported</video><br />
<input type="text" id="videoFile" size="60" placeholder="Enter video file URL here"/>
  <button onclick="playVideo(this);">Play</button>
  <button onclick="hidecontrol(this);">Hide controls</button>



To change the URL that is currently playing, assign it to src. This method sets paused to false. To change the URL using the source element, or if the original video was specified by the source element, call load before calling play.

Standards information

See also

Related pages

  • mediamedia
  • audio
  • audio
  • video