height Property - Javascript CSS Style Property

Javascript examples for CSS Style Property:height

Description

The height property sets or gets the height of an element.

Property Values

Value Description
autoThe browser sets the height. This is default
length Defines the height in length units
% Defines the height in percentage of the parent element
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Technical Details

Item Value
Default Value: auto
Return Value: A String, representing the height of an element
CSS VersionCSS1

Set the height of a <button> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/c.png" style="width:100px;height:132px;">
<br>

<button type="button" onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w w w. j a  v  a2 s .  c om*/
    document.getElementById("myImg").style.height = '20px';
}
</script>

</body>
</html>

Related Tutorials