Video widthProperty

Video 对象参考手册Video Object

Examples

Modify 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:Specifying the height and width of a video is a good practice. 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 video's dimensions in advance, and thus cannot reserve appropriate space for the video. As a result, the layout will change during page loading.

Note:Do not use the height and width attributes to scale videos! Reducing a video with the height and width attributes will only force users to download the original video (even if it appears smaller on the page). The correct approach is to compress the video with software before using it on a web page.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the width property.

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


Syntax

Return 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

Examples

Get the width of the video:

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

xThe output value is:

320

Try it Yourself »


Related Pages

HTML Reference Manual:HTML <video> width Property


Video 对象参考手册Video Object Other Extensions