1 out of 4 rated this helpful - Rate this topic

height Attribute | height Property

Gets or sets the height of the object.

Syntax

CSS { height : sHeight }
Scripting [ sHeight = ] object.style.height

Possible Values

sHeight String that specifies or receives one of the following values.
auto
Default.  
height
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 CSS Length Units Reference.
percentage
Integer followed by a percent sign (%). The value is a percentage of the height of the parent object, which must be 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.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Remarks

If you specify the height property of an img object but not the width property, the width is proportional to the height according to the dimensions of the image source file.

To perform operations on the numeric value of this property, use pixelHeight or posHeight.

As of Microsoft Internet Explorer 6, when you use the !DOCTYPE declaration to specify standards-compliant mode, this property specifies the distance between the top and bottom 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 Windows Internet Explorer, this property includes the object's content box, plus the values of the following properties: borderTop, borderBottom, paddingTop, and paddingBottom. Subtracting the sum of the values of these properties from the value of the height property equals the height of the parent object's content box.

Examples

This example uses an inline style sheet to set the height of an image to 4 centimeters.


<img src="sphere.jpg" style="height: 4cm">

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/height_h.htm

This example uses inline scripting to change the height of an image when an onclick event occurs.


<button onclick="height1.style.height='1cm'">Shrink sphere</button>

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/height_s.htm

Standards Information

This property is defined in Document Object Model (DOM) Level 1 and is defined in Cascading Style Sheets (CSS), Level 1 (CSS1).

Applies To

A, ABBR, ACRONYM, ADDRESS, APPLET, B, BDO, BIG, BLOCKQUOTE, BUTTON, CAPTION, CENTER, CITE, CODE, CSSStyleDeclaration, currentStyle, CUSTOM, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, hn, HR, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, runtimeStyle, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TD, TEXTAREA, TH, TR, TT, U, UL, VAR, XMP, CSSCurrentStyleDeclaration Constructor, CSSRuleStyleDeclaration Constructor, CSSStyleDeclaration Constructor, HTMLInputElement Constructor, HTMLObjectElement Constructor, HTMLTableRowElement Constructor

See Also

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ