Skip to content

CSS Percentage Height with No Parent Height

Quick summary

You set height: 100% but the parent has height: auto — the percentage has no reference and the element is only as tall as its content.

Why this happens

  • Parent has no explicit height (defaults to auto)

  • Chaining height: 100% through multiple ancestors with no fixed height

  • Using percentage height in a flex/grid context where it does not apply

Minimal example

✗ Broken code
.parent { /* height: auto — no reference */ }
.child { height: 100%; /* collapses to content */ }
✓ Fixed code
.parent { height: 100vh; }
.child { height: 100%; /* now fills the viewport */ }

height: 100% needs a parent with a definite height. With the parent at 100vh, the child's 100% resolves against the viewport and fills it.

How to diagnose

  • Inspect the element's computed height in DevTools — it is content-based

  • Walk up the ancestor chain and check each one's height

  • Use height: 100vh or flex: 1 as alternatives

How to fix

  • Set an explicit height on the parent (px, vh, or flex-basis)

  • Use height: 100vh for full-viewport height without depending on parent

  • Use flexbox with flex: 1 to fill available space

How to prevent

  • Use vh or flex for full-height layouts instead of percentage chains

  • Set explicit heights on ancestors when using percentage heights

Related Resources

Related Glossary

Related Lessons

  • CSS

    Learn about sizing.

← Back to language