When you use the
!DOCTYPE declaration to specify standards-compliant mode, this property specifies only the distance between the left and right edges of the content boxthat is, within the
padding.
Syntax
HTML
{ width : sWidth }
Scripting
object.style.width [ =sWidth ]
Possible Values
sWidth
Variant that
specifies or receives one of the following values.
auto
Default. Default width of the object.
width
Floating-point number, followed by an absolute units designator (cm, mm, in, pt, pc, or px) or a relative units designator (em or ex). For more information about the supported length units, see>CSS Length Units.
percentage
Integer, followed by a %. The value is a percentage of the width of the parent object, whether or not it is specified explicitly. Negative values are not allowed.
The property is read/write
for all objects except the following, for which it is read-only:
currentStyle.
The property has a default value of
auto. The Cascading Style Sheets (CSS) attribute is
not inherited.
Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see About Dynamic Properties.
Remarks
As of 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 boxthat 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 object's content box, plus the values of the following properties: borderLeft,>borderRight,>paddingLeft, and>paddingRight. Subtracting the sum of the values of these properties from the value of the width property equals the width of the parent object's content box.
To perform operations on the numeric value of this property, use>pixelWidth or>posWidth.
For more information about how to access the dimension and location of elements on the page through the Dynamic HTML (DHTML)Â Document Object Model (DOM), see>Measuring Element Dimension and Location.
Examples
This example uses an inline style sheet to set the width of an image.The following examples use the width attribute and the width property to change the width of the object.
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
This example uses inline scripting to set the width of an image when an onclick event occurs.
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
Standards Information
property is defined in
World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 and
defined in
Cascading Style Sheets (CSS), Level 1 (CSS1) .