Video width attribute

Definition and Usage

width attribute sets or returns the video's width attribute value.

width The attribute specifies the width of the video player in pixels.

Tip:Always specify the height and width properties of the video. If height and width are set, the space required by the video is reserved when the page is loaded. However, if these properties are not set, the browser will not know the size of the video and cannot reserve appropriate space for it. The page layout will change during loading (when the video is loading).

Note:Do not use height and width properties to resize the video! Shrinking a large video with height and width properties will force the user to download the original video (even if it looks very small on the page). The correct way to resize the video is to use it in a program and then use it on the page.

Example

Example 1

Change the width of the video player:

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

Try it yourself

Example 2

Get the width of the video:

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

Try it yourself

Syntax

Return the width property:

videoObject.width

Set width attribute:

videoObject.width = pixels

Attribute Value

Value Description
pixels Specifies the width of the video player in pixels.

Technical Details

Return Value: Number, indicating the width of the video in pixels.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 9.0 Support Support Support

Related Pages

HTML Reference Manual:HTML <video> width Attribute