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.
<img src="/img/html/poppies.jpg" width="315"
alt="Poppies, by Van Gogh" />
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). |
Here is when width support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |