Export (0) Print
Expand All

height property

Sets or retrieves the height of the object.

Syntax

height: height | percentage | auto

Property 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 Values and 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.

CSS information

Applies ToAll elements
Mediavisual
Inheritedno
Initial Value

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: border-top, border-bottom, padding-top, and padding-bottom. 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.

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


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

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

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


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

See also

CSSStyleDeclaration
currentStyle
runtimeStyle
style
Conceptual
Measuring Element Dimension and Location with CSSOM in Internet Explorer 9
Other Resources
CSS Enhancements in Internet Explorer 6

 

 

Show:
© 2014 Microsoft