W3Schools.com

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.


Definition and Usage

The width attribute specifies the width of an image.

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.


Syntax

<img width="pixels|%" />

Attribute Values

Value Description
pixels The width in pixels (like "100px" or just "100")
% The width in percent of the containing element (like "20%")


HTML img Tag Reference HTML <img> tag
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE