YouTip LogoYouTip

Prop Video Width

HTML DOM Video width Property

HTML DOM Video width Property

-- Learning is not just about technology, but also about dreams!

JavaScript Reference

Overview

JavaScript Objects

Browser Objects

DOM Objects

HTML Objects

HTML DOM Track Object

HTML DOM Video videoTracks Property

Video width Property

Video Object Reference Video Object

Example

Change the width of the video player:

document.getElementById("myVideo").width = "500";

Try it yourself Β»


Definition and Usage

The width property is used to set or return the width of the video player.

The width property describes the width of the video player, in pixels.

Tip: It is a good practice to specify the height and width of the video. If these attributes are set, space will be reserved for the video when the page loads. If these attributes are not set, the browser cannot determine the size of the video, and therefore cannot reserve the appropriate space for it. As a result, the layout of the page will change during loading.

Note: Do not scale the video using the height and width attributes! Scaling the video down using the height and width attributes only forces the user to download the original video (even if it appears smaller on the page). The correct way is to compress the video using software before using it on the webpage.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the width property.

Note: Internet Explorer 8 and earlier IE versions do not support the <video> element.


Syntax

Get the width property:

videoObject.width

Set the width property:

videoObject.width=pixels

Property Values

Value Description
pixels Describes the width of the video player, in pixels (e.g., width="100")

Technical Details

Return Value: A number representing the width of the video, in pixels.

More Examples

Example

Get the width of the video:

var x = document.getElementById("myVideo").width;

The value of x will be:

320

Try it yourself Β»


Related Pages

HTML Reference: HTML <video> width Attribute


Video Object Reference Video Object

← Ruby CgiMet Video Pause β†’