The height property controls how tall an element is on the page. You will learn fixed sizes, percentage sizing, viewport units, and when to let the browser calculate height automatically.
01
Vertical Size
Control box height.
02
auto
Default behavior.
03
Pixels
Fixed heights.
04
Percentages
Relative sizing.
05
Viewport
vh units.
06
Responsive
Flexible layouts.
Fundamentals
Introduction
The height property in CSS is used to set the height of an element. It lets you define how tall a box should be in absolute terms (such as pixels) or relative terms (such as percentages or viewport units).
Proper use of height is crucial for creating responsive and well-structured web layouts. You will use it on cards, heroes, sidebars, images, and any element where vertical space matters.
Definition and Usage
Apply height to block-level elements, inline-block elements, replaced elements, and flex or grid items. The syntax is simple: choose a length, percentage, keyword, or viewport unit.
💡
Beginner Tip
Start with height: auto unless you have a clear reason to fix the size. Fixed heights can cause overflow when content grows on smaller screens.
Foundation
📝 Syntax
The syntax for the height property is simple and versatile:
syntax.css
element{height:value;}
Here, value can be any valid length, percentage, keyword, or viewport unit.
The default value of the height property is auto, which means the browser calculates height based on content, padding, borders, and other applied styles.
Syntax Rules
Works on block-level, inline-block, and replaced elements.
Accepts length units (px, rem, em), percentages, and viewport units (vh, svh).
The property is not inherited.
Percentage heights require a parent with an explicit height.
Pair fixed heights with overflow when content may exceed the box.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
auto
Applies to
All elements except non-replaced inline elements, table columns, and column groups
Inherited
No
Animatable
Yes, as a length
Common use
Cards, heroes, sidebars, images, and layout containers
Reference
💎 Property Values
Value
Description
auto
The browser calculates the height from content and other styles.
length
Defines a fixed height in units such as px, em, rem, etc.
percentage
Sets the height as a percentage of the containing block’s height.
max-content
The intrinsic height of the content.
min-content
The minimum intrinsic height of the content.
fit-content
Clamps the height between min-content and max-content.
Units
Understanding Height Units
Choosing the right unit makes layouts easier to maintain. Here is when each type works best:
px — Best for small UI pieces with a predictable size, such as icons or thumbnail boxes.
rem / em — Scales with font size, useful for components that should grow with text settings.
% — Fills part of a parent container. The parent must have a defined height.
vh — Relative to the viewport height. Common for full-screen hero sections.
auto — Lets content determine height. Usually the safest default for text blocks.
⚠
Percentage Height Rule
If height: 50% seems to do nothing, check the parent. Percentage height only works when the containing block has an explicit height set.
Preview
👀 Live Preview
Three boxes with different fixed heights in pixels:
80px
120px
160px
Hands-On
Examples Gallery
Set fixed pixel heights, percentage heights, full viewport sections, and compare auto against a fixed size.
🔢 Fixed & Relative Heights
Start with the reference example — a div with a fixed height of 200 pixels.
Example 1 — Fixed Height in Pixels
Set a box to exactly 200 pixels tall, regardless of content.
Fixed height box. Extra content scrolls inside when it does not fit.
How It Works
With auto, the box grows with content. With a fixed height, overflow may need overflow: auto or hidden.
A11y
♿ Accessibility
Avoid clipping important content — Fixed heights can hide text when users zoom or increase font size.
Allow content to grow — Prefer min-height over rigid height for text-heavy areas.
Test keyboard and touch targets — Ensure buttons and links remain reachable inside fixed-height containers.
Do not rely on height alone for meaning — Visual size should not be the only indicator of importance.
Check mobile viewports — Full 100vh sections can feel too tall on small screens with browser chrome.
🧠 How height Works
1
You set a height value
Choose auto, a length like 200px, a percentage, or a viewport unit.
CSS rule
2
The browser resolves the size
Percentages look at the parent height. Viewport units look at the window. auto uses content size.
Calculation
3
The box is rendered
Padding and borders add to the total space the element occupies in layout, depending on box-sizing.
Layout
=
↕
Controlled vertical space
Your layout gets predictable or flexible height depending on the value you chose.
Compatibility
🖥 Browser Compatibility
The height property is universally supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Older versions of Internet Explorer also support basic height values.
✓ Baseline · Universal support
Fundamental layout property
height has been part of CSS since the earliest layout models and works consistently across browsers.
99%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
OperaAll modern versions
Full support
height property99% supported
Bottom line: You can rely on height in production layouts across all major browsers.
Wrap Up
🎉 Conclusion
The height property is a fundamental CSS tool for controlling the vertical size of elements. By understanding units such as pixels, percentages, and viewport heights, you can create flexible, responsive, and visually appealing web designs.
For beginners, the main idea is simple: use auto by default, add fixed heights when you need predictable boxes, and remember that percentage heights depend on the parent container.