English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Comprehensive CSS Properties

CSS height attribute usage and examples

The height CSS attribute specifies the height of the content area of an element. The content area does not include padding, border, or margin. More information can be found inCSS box model.

The following table explains the usage and version history of this attribute, as well as the syntax of using this attribute in JavaScript scripts.

Default value:auto
Applies to:Except for unreplaced embedded elements,
All elements outside table rows and row groups
Inheritance:No
Can be animated:Yes.Please refer to Animation attributes.
Version:CSS 1,2,3
JavaScript syntax:object.style.height="100px"

Syntax of height usage

The syntax of this attribute is as follows:

height: length | percentage | auto | initial | inherit

The following example demonstrates how to use the height attribute.

  p {
   height: 50px;
   background-color: #f0e68c;
  }
Test to see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
lengthSpecify the height in units such as px, pt, cm, em, etc., and the height cannot be negative.
percentageSpecify the height as a percentage. The percentage is calculated relative to the height of the element's containing block. Negative percentage values are not allowed.
autoThe browser will calculate the height of the specified element based on the values of other attributes. This is the default value.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts the height attribute value of its parent element.

Browser compatibility

Browser compatibility of the height attribute, the numbers in the table below represent the minimum version number of the browser that supports this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Read more

Please refer to the tutorials related to the following content:CSS Box Model,CSS dimensions.

Related attributes:max-height,min-height.