Easy Tutorial
❮ Att Link Rev Att Td Width ❯

HTML <img> width Attribute

HTML <img> Tag

Example

An image with both height and width set to 42 pixels:


Browser Support

All major browsers support the width attribute.


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

Tip: It is a good practice to specify the height and width attributes for an image. If these attributes are set, space is reserved on the page when the image is loading. Without these attributes, the browser cannot know the size of the image, and thus cannot reserve appropriate space for it, resulting in layout changes when the image loads.

Tip: Do not scale the image using the height and width attributes. If you reduce the image size with these attributes, the user still has to download the large image (even if it appears small on the page). The correct approach is to resize the image to the appropriate size using software before using it on a webpage.


Differences Between HTML 4.01 and HTML5

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


Syntax

Attribute Values

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

❮ Att Link Rev Att Td Width ❯