Sets the width of the object.
Variant that specifies or receives one of the following values:
Default. Default width of the object.
Integer, followed by a percent sign (%). The value is a percentage of the width of the parent object, whether or not it is specified explicitly. Negative values are not allowed.
Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).
For more information about the supported length units, see Length units reference.
The property has a default value of auto. It is not inherited.
As of Microsoft Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, this property specifies the distance between the left and right edges of the content box—that is, within the padding.
When the !DOCTYPE declaration does not specify standards-compliant mode, and with earlier versions of Internet Explorer, this property includes the content box of the object, plus the values of the following properties: border-left, border-right, padding-left, and padding-right. Subtracting the sum of the values of these properties from the value of the width property gives you the width of the content box of the parent object.
The following example uses an inline style sheet to set the width of an image. This example uses the width property to change the width of the object:
<div style="position:absolute;top:10px;left:10px;width:1in"> . . . </div>
This example uses inline scripting to set the width of an image when an onclick event occurs:
<img src="sphere.jpg" onclick="this.style.width='1cm'" ondblclick="this.style.width=''">
This property is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 and in Cascading Style Sheets (CSS), Level 1 (CSS1).