{{CSSRef()}}
Summary
The height
CSS property specifies the height of the content area of an element. The content area is inside the padding, border, and margin of the element.
The {{Cssxref("min-height")}} and {{Cssxref("max-height")}} properties override {{Cssxref("height")}}.
{{cssbox("height")}}
Syntax
height: auto; /* <length> values */ height: 120px; height: 10em; /* <percentage> value */ height: 75%; /* Global values */ height: inherit; height: initial; height: unset;
Values
<length>
- See {{ Xref_csslength }} for possible units.
<percentage>
- Specified as a {{ Xref_csspercentage }} of containing block's height.
border-box
{{ experimental_inline }}- If present, the preceding {{ xref_csslength}} or {{ xref_csspercentage }} is applied to the element's border box.
content-box
{{ experimental_inline }}- If present, the preceding {{ xref_csslength}} or {{ xref_csspercentage }} is applied to the element's content box.
auto
- The browser will calculate and select a height for the specified element.
max-content
{{ experimental_inline }}- The intrinsic preferred height.
min-content
{{ experimental_inline }}- The intrinsic minimum height.
available
{{ experimental_inline }}- The containing block height minus vertical margin, border and padding.
fit-content
{{ experimental_inline }}- The larger of:
- the intrinsic minimum height
- the smaller of the intrinsic preferred height and the available height
Formal syntax
{{csssyntax2}}
Example
HTML
<div id="red"> <span>I'm 50 pixels tall.</span> </div> <div id="green"> <span>I'm 25 pixels tall.</span> </div> <div id="parent"> <div id="child"> <span>I'm half the height of my parent.</span> </div> </div>
CSS
div { width: 250px; margin-bottom: 5px; border: 3px solid #999999; } #red { height: 50px; } #green { height: 25px; } #parent { height: 100px; } #child { height: 50%; width: 75%; }
{{ EmbedLiveSample('Live_sample') }}
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS3 Box', '#the-width-and-height-properties', 'height')}} | {{Spec2('CSS3 Box')}} | Added the max-content , min-content , available , fit-content , border-box , content-box keywords. |
{{SpecName('CSS3 Transitions', '#animatable-css', 'height')}} | {{Spec2('CSS3 Transitions')}} | Lists height as animatable. |
{{SpecName('CSS2.1', 'visudet.html#the-height-property', 'height')}} | {{Spec2('CSS2.1')}} | Adds support for the {{xref_csslength()}} values and precises on which element it applies to. |
{{SpecName('CSS1', '#height', 'height')}} | {{Spec2('CSS1')}} | Initial specification. |
Browser compatibility
{{CompatibilityTable()}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1")}} | 4.0 | 7.0 | 1.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoMobile("1")}} | 6.0 | 6.0 | 1.0 |
See also
- box model, {{Cssxref("width")}}, {{Cssxref("box-sizing")}}, {{Cssxref("min-height")}}, {{Cssxref("max-height")}}