English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The width attribute specifies the width of the image in pixels.
Height and width are both 30 Pixel Image:
<!DOCTYPE html> <html> <head> <title>HTML: <img> width Attribute</title> - Basic Tutorial Website oldtoolbag.com</title> <body> <img src="haha.gif" alt="haha face" width="30" height="30> </body> </>Test to see </›
IEFirefoxOperaChromeSafari
All mainstream browsers support the width attribute.
The width attribute specifies the width of the image in pixels.
Tip:Always specify both the height and width attributes of the image. If height and width are set, the space required for the image is reserved when loading the page. However, if these attributes are not set, the browser will not know the size of the image and will not be able to reserve appropriate space for it. The effect is that the page layout will change during loading (when the image is loaded).
Tip:Using the height and width attributes to shrink the size of large images will force users to download the large image (even if it looks very small on the page). To avoid this, please resize the image programmatically before using the page.
In HTML 4.01 In the syntax, the width should be defined in pixels or as a percentage of the containing element. In HTML5 In the syntax, the width value must be specified in pixels.
<img width="pixels">
Value | Description |
---|---|
pixels | Width in pixels (for example width="100") |