.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).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("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")
Call
What it does
.height()
Learn jQuery .height(): get or set content height as a unitless pixel Number, compare with .css('height'), window and document heights, callback setter, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Select the element(s) with jQuery.
Step 2
Call .height() with no args to read a unitless pixel Number.
Step 3
Pass a Number (pixels) or CSS string to set height on every match.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Get Element, Document, and Window Height
Official-style reads: paragraph, full page, and viewport.
Dimension helper..height() strips units and returns a Number.
CSS getter..css("height") keeps the computed string (often with px).
Math. Multiply the Number directly — no parseInt needed.
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.