HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML <img> width Attribute

HTML img Tag Reference HTML <img> tag

Example

An image with a height and a width of 42 pixels:

<img src="smiley.gif" alt="Smiley face" height="42" width="42">

Try it Yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The width attribute is supported in all major browsers.


The width attribute specifies the width of an image, in pixels.

Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the images load).

Tip: Downsizing a large image with the height and width attributes forces a user to download the large image (even if it looks small on the page). To avoid this, rescale the image with a program before using it on a page.


Differences Between HTML 4.01 and HTML5

In HTML 4.01, the width could be defined in pixels or in % of the containing element. In HTML5, the value must be in pixels.


Syntax

<img width="pixels">

Attribute Values

Value Description
pixels The width in pixels (e.g. width="100")


HTML img Tag Reference HTML <img> tag

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE