.height() gets or sets the content height of matched elements (since jQuery 1.0). The getter returns a unitless pixel Number — ideal for math. It also works on $(window) and $(document).
Remember
$("div").height() // Number → content height (px)
$("div").height(100) // set 100px
$("div").height("50%") // set with CSS units
$(window).height() // viewport height
$(document).height() // full page height
.height() → Number (unitless)
.css("height") → String ("80px")
Pick getter or setter, then choose the box edge you really need.
Select the element(s) with jQuery.
Call .height() with no args to read a unitless pixel Number.
Pass a Number (pixels) or CSS string to set height on every match.
Use the callback form when each element needs a different value.
Piece
Required?
Role
jQuery selection
Yes
Element(s), window, or document
value / function
Setter only
New height (Number, string, or per-element fn)
Return
—
Getter → Number; setter → jQuery (chainable)
Pseudocode
Pseudocode
function height(selection, value):
if value is missing:
el = first matched element
return contentHeight(el) as Number // no "px"
for each el in selection:
if value is a function:
newH = value(index, currentHeight)
else:
newH = value
set CSS height of el to newH // Number → pixels
return selection
Reference
Cheat Sheet
Keep these facts handy while measuring vertical size.
Topic
Detail
Syntax
.height() / .height(value) / .height(fn)
Since
1.0 (callback setter: 1.4.1)
Getter returns
Unitless pixel Number (may be fractional)
Measures
Content height (padding & border excluded)
box-sizing
Still reports content height (extra work if border-box)
Window / document
$(window).height() / $(document).height()
vs .css("height")
Number vs string with units
Try it
Live Preview
Pick an action against the sample box and see what .height() returns or sets.
Browser demo of .height() — same idea as the examples below.
Sample box
Result
$("#box").height()
→ 60
typeof result → "number"
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Get Element, Document, and Window Height
Official-style reads: paragraph, full page, and viewport.
Callback. jQuery calls your function once per matched element.
Args. First argument is the zero-based index; second is the current height.
Return. Return a Number (or CSS string) to set that element’s height.
Pattern. Great for bar charts and staggered panels without a manual loop.
Edge Cases & Pitfalls
Check these before trusting .height() in layout code.
hidden
Hidden elements can report 0
Measure while the element is visible. Do not rely on temporary show/hide measurement.
box
border-box still returns content height
Since 1.8, jQuery may subtract padding/border to keep the content-height contract — that costs extra work. Use .css("height") if you only need the CSS property string.
fraction
Values may be fractional
Sub-pixel layouts can return numbers like 80.5. Round only when your UI needs integers.
tags
Avoid style / script tags
Calling .height() on those tags is unreliable and discouraged by the official API.
Compatibility
Browser Support
.height() has shipped since jQuery 1.0 (callback setter since 1.4.1) and works in all modern browsers with jQuery loaded.
✓ jQuery 1.0+
.height()
Core dimension API for content height — getter returns a unitless Number; setter accepts Number, string, or function.
100%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
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.height()Excellent
Bottom line: Use .height() for content-height math. Prefer .innerHeight() / .outerHeight() when padding or border must be included.
Analysis
Performance Notes
Approach
Cost
Best for
.height()
Layout read
Content-height math
.css("height")
Cheaper read
CSS string / avoid border-box math
Repeated reads in a loop
Can thrash layout
Cache the Number first
Dimension getters force layout. Read once, reuse the Number, and avoid calling .height() inside tight animation frames unless needed.
Remember
Key Takeaways
Role: get/set content height as a unitless pixel Number.
Math: prefer .height() over parsing .css("height").
Box edges: use innerHeight / outerHeight when padding or border matters.
One line:.height() is your content-height Number — get for math, set with a Number/string/callback, and switch to inner/outer when the box edge changes.
Frequently Asked Questions
.height() with no arguments returns the content height of the first matched element as a unitless pixel Number. .height(value) or .height(function) sets the CSS height on every matched element and returns the jQuery object for chaining.
.height() returns a Number like 80 — ready for math. .css('height') returns a string such as '80px' or 'auto'. Prefer .height() for calculations and animations; use .css('height') when you need the literal CSS value.
No. .height() measures content height only. Use .innerHeight() for padding, and .outerHeight() for padding plus border (pass true to include margin).
$(window).height() is the viewport height. $(document).height() is the full scrollable page height. Both return unitless Numbers.
Since jQuery 1.4.1, .height(function(index, height)) runs once per matched element. Return a Number or CSS string to set that element's height. Handy for staggered layouts and bar charts.
No. Values can be wrong (often 0) when the element or a parent is hidden. Measure while visible. Fractional pixels are possible — do not assume an integer.