CSS Attributes Index Positioning Properties
Sets or retrieves the height of the object.
CSS |
{ height: 'auto' | length | percentage } |
Script |
object.style.height = sHeight ] |
auto |
Default height. |
length |
Floating-point number and a valid CSS length unit: either an absolute units designator ( cm, mm, in, pt, pc, or px ) or a relative units designator ( em or ex ). |
percentage |
Value expressed as a percentage of the parent object’s height. |
The property is read/write with a default value of auto; the CSS attribute is not inherited.
The height of a block object encompasses border-top, border-bottom, padding-top, padding-bottom, margin-top, margin-bottom, and height the sum of which equals the height of the parent's content.
Percentage values refer to the parent object’s height. Negative values are not allowed.
To carry out operations on the numeric value of this property, use pixelHeight or posHeight.
For more information on how to access the dimension and location of objects on the page through the document object model, see Measuring Element Dimension and Location.
The sample below uses an inline stylesheet to set an image element’s height attribute.
<img src="sample.jpg" style="height:50px">
Show me
The sample below uses inline event handlers to dynamically change an object’s height property on an onclick event.
<button onclick="theImg.style.height='75px'">
Change Height</button>
Show me
width