CSS2 » Properties » width

Version: No

width : length | percentage | auto
The auto value directs the browser to automatically calculate the width. If both the width and height are set to auto, the dimensions of the text or image element remains unchanged. By declaring auto, you can ensure that any previous declaration will not effect the width of the selected element.
The percentage value is based upon the total width being defined as 100%.
The length value can be in any of the following seven dimensions. Use the abbreviation.
Length Abbrev.
centimeters cm
ems em
inches in
millimeters mm
picas pc
pixels px
points pt

The width property allows you to set the width of an element of text or an image. This property is not inherited.

For example, you could embed an image into a specified position within a text using the float property. Then use the width and/or height properties to specify an exact size for the image. If you set the width of an element to a specified value and set the height property to auto, the element will be scaled proportionally (i.e., you maintain the aspect ratio).


img { width: 150mm; }
img { width: 2.85in; }
img { width: 45pc; }
img { width: 36pt; }
img { width: 140%; }
img { width: auto; }
img {
width:  3.0in
height: auto
Language(s): CSS2
<img src="/images/guru.gif">
<img src="/images/guru.gif" style="width: 55px; height: auto;">
Devguru logo Devguru logo
Language(s): CSS2

See Also: