Set Height & Width

The height and width properties are used to control the height and width of an element. These properties can be set to auto (this is default, which means that the browser calculates the height and width), or be specified in length values, like px, cm, etc., or in percent (%) of the containing block (element).

The following example shows a <div> element with a height of 100 pixels and a width of 500 pixels:

CSS code: Displayed by browser:
div {
    width: 500px;
    height: 100px;
    border: 3px solid #8AC007;
}
This <div> element has a height of 100 pixels and a width of 500 pixels.

Note: The height and width properties do not include padding, borders, or margins; they set the height/width of the area inside the padding, border, and margin of the element!

Back button Table of Contents Next button