width

Sets the width of the object.

Syntax

{ width: sWidth }

Possible values

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.

Remarks

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.

Examples

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

Standards information

Applies to

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

See also

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.

Community Additions

ADD
Show: