HTML img width Attribute
HTML <img> tag
Definition and Usage
The width attribute specifies the width of the image.
The height, and width attributes are set to let the browser know how big the
image is, so it can reserve space for the image in the page layout. If these
attributes are not set, the site layout will change during loading (while
waiting for images to load).
Note: Rescaling images is not good coding practice. Downsizing a large
image to fit your site will use more bandwidth than necessary. It is better to
manually rescale the image before using it in your website.
Syntax
Syntax Example
Attribute Values
Value |
Description |
pixels |
Specify image width in pixels (like "100px", or just "100") |
percent |
Specify image width in percent of the containing element
(like "20%") |
Browser Support

The attribute is supported in all major browsers.
Example
Source |
Output |
<img src="demo_img.jpg"
alt="W3Schools example picture"
width="150" />
|
|
Note: As you can see in the example, if the width attribute
is set by itself (without setting the height attribute), the image will be
properly rescaled. However, if the height attribute is set, and the
width attribute is changed, the image will be stretched.
Try-It-Yourself Demos
img width
attribute example
Specify the width of an image.
HTML <img> tag
 |

|
|
See why there are 20,000+ Ektron integrations worldwide.
Request an INSTANT DEMO or download a FREE TRIAL today. |
|
|
|