Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Box Model and Sizing

The height property

Reference for the CSS height property: lengths, percentages, auto, content keywords and viewport units, why percentage heights fail, and how to avoid clipping.

The height property sets the preferred height of an element's box. With the default auto, the box is as tall as its content needs, which is almost always what you want for text. Fixed heights are useful for media, bars and decorative boxes, but they are a common source of overflowing and clipped content when text grows.

As with width, the value applies to the content box unless box-sizing is border-box.

CSS
.banner { height: 200px; }
.page { min-height: 100vh; }

Try it

Fixed height and overflow

Syntax

CSS
height: auto
      | <length-percentage [0,โˆž]>
      | min-content | max-content | fit-content | fit-content(<length-percentage>)
      | stretch;
  • Initial value: auto
  • Applies to: all elements except non-replaced inline elements, table columns and column groups
  • Inherited: no
  • Animatable: yes, as a length, percentage or calc(). Animating to or from auto needs interpolate-size: allow-keywords or calc-size(), which have limited support.
  • Computed value: a percentage or auto as specified, otherwise an absolute length

Values

Value Description
auto Height is determined by the content and layout mode.
<length> A fixed size such as 300px, 20rem or 50vh.
<percentage> A percentage of the containing block's height, but only if that height is explicitly set; otherwise it behaves like auto.
min-content, max-content, fit-content Content-based keywords. In horizontal writing modes they usually equal auto.
stretch Fill the available height of the container. Newer, with limited support.

Usage notes

  • Percentage heights are the classic trap. height: 100% does nothing unless every ancestor up to the root has a definite height. Use min-height: 100vh, 100dvh or a flex or grid layout instead.
  • Prefer min-height to height for containers with text. The box can grow when the content, translation or font size requires.
  • Fixed heights cause overflow. If you must fix a height, decide what happens to extra content: overflow: auto, hidden, or a design that cannot overflow.
  • 100vh on mobile. The classic viewport can be taller than the visible area when browser toolbars show. 100dvh follows the visible area, 100svh always fits the smallest.
  • Images. Set only width and use height: auto, or set aspect-ratio, to avoid distortion and layout shift.
  • Writing modes. height is physical. Use block-size for a size that follows the writing direction.

Browser support

Supported in every browser. Dynamic viewport units (dvh, svh, lvh) are supported in all current browsers.