WIDTH Attribute | width Property

DHTML, HTML, & CSS

WIDTH Attribute | width Property


Sets or retrieves the calculated width of the object.

Syntax

HTML<ELEMENT WIDTH = sWidth ... >
Scriptingobject.width [ = sWidth ]

Possible Values

sWidth String that specifies one of the following values:
widthInteger that specifies the width of the object, in pixels.
percentageInteger, followed by a %. The value is a percentage of the width of the parent object.

This property is read/write for the IMG object and read-only for other objects. There is no default value.

Remarks

If you specify the width property of an IMG, but not the height property, the resulting height of the IMG is sized proportionally to the specified width property and the actual height, in pixels, of the source image file. Consider the following example:

Dimensions of image in source file (pixels):100 X 50 (W X H)
Specified image width:2in
Specified image height:not specified
Resulting image width:2in
Resulting image height:1in ((50/100) * 2 inches)

If you specify the width property of an IMG, and the height and width of the image in the source file are identical, the height of the image matches the width.

If you specify the height property and the width property of an IMG, the resulting image dimensions match the height and width specified.

Although you can specify the width as a percentage, this property always retrieves the width in pixels.

Example

This example sets the width of the image to 20 pixels regardless of the original size of the image.

Sample Code

<IMG SRC="large.gif" WIDTH="20">

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
COL, COLGROUP, EMBED, FRAME, HR, IMG, MARQUEE, OBJECT, TABLE, TD, TH, TR

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.