width

Sets the width of the object.

{ width: sWidth }

sWidth

Variant that specifies or receives one of the following values:

auto

Default. Default width of the object.

percentage

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.

width

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=''">

A, ABBR, ACRONYM, ADDRESS, APPLET, B, BDO, BIG, BLOCKQUOTE, BUTTON, CAPTION, CENTER, CITE, CODE, CUSTOM, DD, DEL, DFN, DIV, DL, DT, EM, FIELDSET, FONT, FORM, HN, HR, I, INS, LI, OL, OPTION, P, Q, RT, RUBY, S, SELECT, SPAN, SUB, TT, U, UL, VAR, XMP

Community Additions

ADD
Show: