Style heightProperty
Style Object
Definition and Usage
The height property sets or returns the height of an element.
The height property only takes effect on block-level elements or elements with absolute/fixed positioning. Overflow content can be limited by the overflow property.
Syntax
Set the height property:
Object.style.height="auto|length|%|inherit"
Return the height property:
Object.style.height
| Value | Description |
|---|---|
| auto | Default. The height set by the browser. |
| length | Defines the height in units such as px, cm. |
| % | Defines the height as a percentage of the parent element. |
| inherit | The value of the height property is inherited from the parent element. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the height property.
Note:IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Set the height of a button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function displayResult(){
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Modify button height">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example(example.com)</title>
<script>
function displayResult(){
document.getElementById("b1").style.height="50px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="displayResult()" value="Modify button height">
</body>
</html>
Try it Yourself »
Style Object Other extensions