Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Dimensions

Done with the previous section? Good, now it's time for the methods that work with element dimensions.

But before we continue, I recommend refreshing your memory on calculating the height and width of block elements ;)

returns the element's height excluding padding and borders; if there are multiple elements in the selection, the first one is returned; unlike the css("height") method, the value is returned without units

sets the height of all elements in the selection; if the height value is passed without units, it will be in pixels px

A note from the manual

$(window).height();   // window height
$(document).height(); // HTML document height

The width() and width(width) methods behave the same as height(), but work with the element's width:

returns the element's width excluding padding and borders; if there are multiple elements in the selection, the first one is returned; the value is returned without units

sets the width of all elements in the selection; if the width value is passed without units, it will be in pixels px

return the element's height and width respectively, including padding

return the element's height and width, including padding and border

return the element's height and width, including padding, border, and margin

To illustrate the differences between height(), innerHeight(), and outerHeight(), I created the following example:

In this example, the central element with id=block has the following styles:

Now let's see what each of these functions returns:

To make it easier to understand what's going on, I went the extra mile and combined several images from the official documentation into one full illustration:

box model

Last updated