Jump to: navigation, search


This article is Ready to Use.

W3C Recommendation


Specifies the width, in pixels, of certain content elements.

Applies to HTMLImgElement

The width attribute specifies the visual width of img, iframe, embed, object, video, canvas, and input[type="image"] in pixels.

By default, elements will not preserve aspect ratio when width attribute is set, without a height attribute. If a width attribute is set, but no height, an image will scale to preserve its original aspect ratio. If both the width and height are zero, the element should not be intended to be visible by the user.

Width values must be non-negative integers.


There is no data available for topic "html", feature "width". If you think that there should be data available, consider opening an issue.


View live example<img> with width attribute.


<img src="http://www.webplatform.org/logo/wplogo_transparent_xlg.png" height="100" width="150">

View live example<canvas> with width attribute


<canvas width="200" height="200"></canvas>

Related specifications

Specification Status Related Changes
HTML4 Specification W3C Recommendation


This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]