Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The width property of the HTMLImageElement interface indicates the width at which the image is drawn, in CSS pixels, if the image is being drawn or rendered to any visual medium such as a screen or printer. Otherwise, it's the natural, pixel density-corrected width of the image.
An integer value indicating the width of the image. The way the width is defined depends on whether the image is being rendered to a visual medium or not.
In this example, two different sizes are provided for an image of a clock using the srcset attribute. One is 200px wide and the other is 400px wide. Further, the sizes attribute is provided to specify the width at which the image should be drawn given the viewport's width.
For viewports up to 400px wide, the image is drawn at a width of 200px. Otherwise, it's drawn at 400px.
The JavaScript code looks at the height to determine the height of the image given the width at which it's currently drawn.
This example may be easier to try out in its own window.
| HTML # dom-img-width-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Nov 7, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.