HTML <img> width Attribute

The width attribute on an <img> tag sets the width of the image.

The width is specified in pixels -- without the ‘px‘ unit.



A width attribute on an <img> element.
The width attribute overrides the original image width.

Poppies, by Van Gogh
<img src="/img/html/poppies.jpg" width="315" 
     alt="Poppies, by Van Gogh" />

Using width

The width attribute specifies the width of the image element.

The width is defined in pixels, without the 'px' unit.

To define the width in % or other unit, use the CSS width property.

The browser will maintain the correct aspect ratio of the image if the height attribute is not set.

Note:  Image width can also be defined with CSS. If both the width attribute and CSS width property are specified, CSS takes precedence (wins).

Tip:  The browser must perform an image resize if the specified width is different from the original image. To speed up the page, it is best to specify the real image size.


<img width="pixels" />



Value Description
pixels A number (e.g. 200).

Browser support

Here is when width support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

 Back to <img>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023

What's your favorite/least favorite part of Dofactory?