/

HTML / CSS / JavaScript Tutorial

CSS Property: height

[this page | pdf | back links]

The CSS (CSS1) height property indicates the height of an element (excluding padding, borders and margins). It is overridden by the min-height or max-height properties, if either of them are present.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

Height as a CSS length (px, cm, …)

%

Height of element defined as a percentage of height of its containing block

auto

(default value). Browser determines height

 

Default Value:

auto

JavaScript syntax:

e.g. object.style.height="200px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {border: 2px solid green; width: 200px;}
p.x1 {height: 50px;}
</style>
</head>
<body>
Element with default property
<p>1</p>
Property set using in-file HTML style
<p class="x1">2</p>
Property set using JavaScript
<p id="x2">3</p>

<script>
document.getElementById("x2").style.height = "50px";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyHeight() {
  var x = document.createElement("DIV"); x.style.height = "50px"; return (window.getComputedStyle(x, null).height == "50px");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile