CSS height Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The height property sets the vertical size of an element. By default it defines the height of the content area. With box-sizing: border-box, it defines the height of the border area instead.

It is not inherited. The initial value is auto. min-height and max-height can override it. For logical sizing in writing modes, see block-size.

Accessibility.

Fixed heights can clip text when users zoom. Prefer auto or min-height when content may grow.

CSS Syntax

syntax.css
height: auto | <length> | <percentage> | min-content | max-content | fit-content | initial | inherit;

There is also a newer stretch keyword with limited support. Start with auto, lengths, and percentages.

Property Values

ValueDescriptionTry it
autoDefault. Browser sizes the box from contentTry it
<length>Fixed size such as 120px, 10em, or 50vhTry it
<percentage>Percent of the containing block’s heightTry it
fit-contentUses available space, capped by max-contentTry it
initialResets to autoTry it
inheritTakes the parent’s heightTry it

How to Use height

Pick a sizing strategy: grow with content, fix a length, or size relative to a parent or the viewport.

  1. Leave height: auto when content should decide the size.
  2. Use a length (px, rem, vh) for a fixed or viewport-based height.
  3. For percentages, give the parent an explicit height first.
  4. Add min-height / max-height when the box must flex with content.
PieceRequired?Role
Block or replaced elementYesNon-replaced inlines ignore height
height valueYesauto, length, percentage, or keyword
Parent with set heightFor %Percentage resolves against the containing block
box-sizingOptionalDecides if padding/border count inside height

Live Preview

Change height on the sample box. Watch it grow or shrink while width stays the same.

The outer frame is 200px tall so 50% has a parent height to resolve against.

Box
Box

height: 80px

CSS Examples

Each snippet focuses on height. Use Try It Yourself for a live editor.

Example 1 — Fixed Length

Set an exact pixel height.

CSS
<style>
  div {
    height: 80px;
  }
</style>

<div>80px tall</div>
Try It Yourself

How It Works

  1. Pick a length. 80px is an absolute content height (with default box-sizing).
  2. Apply to the box. The div becomes 80 pixels tall.
  3. Content may overflow. If text needs more space, use overflow or raise the height.
  4. Other units work too. Try rem, em, or vh the same way.

Example 2 — Percentage of Parent

Size a child as half of a parent that has an explicit height.

CSS
<style>
  .parent {
    height: 160px;
  }

  .child {
    height: 50%;
  }
</style>

<div class="parent">
  <div class="child">Half of parent</div>
</div>
Try It Yourself

How It Works

  1. Give the parent a height. 160px makes the containing block explicit.
  2. Use a percentage on the child. 50% resolves to 80px here.
  3. Without a parent height. Percentage often falls back to auto.
  4. Root exception. Percentage on the root is relative to the initial containing block.

Example 3 — Auto Height

Let content decide how tall the box is.

CSS
<style>
  div {
    height: auto;
  }
</style>

<div>This box grows with its text.</div>
Try It Yourself

How It Works

  1. Use auto. This is the default for most elements.
  2. Content drives size. More text means a taller box.
  3. Safer for zoom. Less risk of clipping when users enlarge text.
  4. Pair with min-height. Keep a floor while still allowing growth.

Edge Cases & Pitfalls

Most height bugs come from percentages or clipping.

percent

Percentage needs a parent height

If the containing block height depends on content (auto), a child height: 50% usually becomes auto.

box

box-sizing changes what height means

With border-box, padding and border are included inside the height. With content-box, they add outside it.

override

min-height / max-height win

Those properties override height when they conflict. Check them if a box will not shrink or grow as expected.

inline

Non-replaced inlines ignore height

A plain span does not take height. Use a block, flex item, or replaced element.

a11y

Fixed height can clip text

When users zoom, fixed heights may hide content. Prefer flexible sizing for text-heavy boxes.

Browser Support

height is a browser layout property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

height

Length, percentage, and auto work everywhere. Keywords like fit-content are widely supported; stretch is newer and limited.

99% Common values
Google Chrome 1+
Full
Mozilla Firefox 1+
Full
Apple Safari 1+
Full
Microsoft Edge 12+
Full
Opera Supported
Full
Samsung Internet Supported
Full
Internet Explorer 4+
Full
height Widely supported

Bottom line: Safe for everyday sizing. Treat stretch as progressive enhancement until support is broad.

Key Takeaways

  • Role: set how tall a box is (content or border box, depending on box-sizing).
  • Common values: auto, lengths, and percentages.
  • Initial value: auto. Not inherited.
  • Percent tip: parent needs an explicit height, or the % often becomes auto.

One line: height controls how tall the box is — auto from content, or a length / percentage you choose.

Frequently Asked Questions

It sets how tall an element is. By default it sizes the content area; with box-sizing: border-box it sizes the border area.
The initial value is auto. The browser sizes the box from its content and layout rules.
A percentage height needs a containing block with an explicit height. If the parent height is auto, the percentage usually computes to auto.
height sets a preferred height. min-height sets a floor so the box can still grow with content. max-height sets a ceiling.
Yes. With content-box (default), height is the content only. With border-box, height includes padding and border.
It is Baseline and widely available in all major browsers. Newer keywords like stretch have limited support. It is a browser layout property, not a Node.js feature.

Next: hyphenate-character

Learn which character CSS uses when hyphenating words.

hyphenate-character tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful