CSS height attribute

Definition and Usage

Sets the height of the element.

Description

This attribute defines the height of the element's content area, and padding, borders, and margins can be added outside the content area.

Inline non-replaced elements will ignore this attribute.

See Also:

CSS Tutorial:CSS Dimensions

CSS Tutorial:Overview of CSS Box Model

CSS Reference Manual:width attribute

HTML DOM Reference Manual:height attribute

Example

Set the height and width of paragraphs:

p
  {
  height:100px;
  width:100px;
  }

Try It Yourself

CSS Syntax

height: auto|length|initial|inherit;

Attribute Value

Value Description
auto Default. The browser will calculate the actual height.
length Define the height using units such as px, cm, etc.
% Based on the percentage height of the containing block-level object.
inherit Specifies that the height attribute value should be inherited from the parent element.

Technical Details

Default Value: auto
Inheritance: no
Version: CSS1
JavaScript Syntax: object.style.height="50px"

TIY Example

Set the height of an image using pixel values
This example demonstrates how to set the height of an element using pixel values.
Set the height of an image using percentage
This example demonstrates how to set the height of an element using percentage values.

Browser support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome IE / Edge Firefox Safari Opera
1.0 4.0 1.0 1.0 7.0