HTML img width property
Examples
The height and width of 42 pixels:
try it"
Browser Support
All major browsers support width attribute.
Width attribute specifies the width of the image in pixels.
Tip: Specify the height and width attributes of the image is a good habit. If you set these properties, you can reserve space for the image when the page loads. Without these attributes, the browser was unable to understand the dimensions of the image, it can not retain the appropriate space for the image, so that when the image is loaded, the page layout will change.
Note: Please do not come through the zoomed image height and width attributes. If by height and width attributes to reduce the image, then the user must download large image (even if the image on the page seem small). The correct approach is to use an image on a Web page before, it should be by the image processing software for the appropriate size.
Differences between HTML 4.01 and HTML5
In HTML 4.01, the width should be defined in pixels or as a percentage of the containing element as a unit. In HTML5, the width value must be in pixels.
grammar
Property Value
值 | 描述 |
---|---|
pixels | 以像素为单位的宽度(比如 width="100") |
HTML <img> tag