HTML DOM Video width Property


The HTML DOM Video width property returns/sets a number corresponding to width (in pixels) of media.

Syntax

Following is the syntax −

Returning width as a number (px)

mediaObject.width

Setting width to a number (px)

mediaObject.width = number

Let us see an example of Video width property −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Video width</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Video-width</legend>
         <video id="demo" height="200" width="170" controls><source
         src="http://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>
         <input type="button" onclick="getTrackDetails()" value="Video Not Visible">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
      var divDisplay = document.getElementById("divDisplay");
      var demo = document.getElementById("demo");
      function getTrackDetails() {
         demo.width += 50;
         divDisplay.textContent = 'Video width: '+demo.width;
      }
   </script>
</body>
</html>

Output

Before clicking ‘Video Not Visible’ button −

Clicking ‘Video Not Visible’ button 3 times −

Updated on: 15-Feb-2021

72 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements