jQuery - Dimensions


Using jQuery makes it simple to handle the size of elements and the web browser window.


jQuery Dimension Methods

jQuery offers various important functions to handle measurements:

  • width()
  • height()
  • innerWidth()
  • innerHeight()
  • outerWidth()
  • outerHeight()

jQuery width() and height() Methods

The width() function does two things: it can either set or tell you the width of an element. This measurement does not include the padding, border, and margin of the element.

The height() function either changes or tells you the size of an element. This size does not include the padding, border, and margin.

This example shows how to find the width and height of a specific <div> element:


jQuery innerWidth() and innerHeight() Methods

The innerWidth() function tells you how wide an element is, including its padding.

The innerHeight() function tells you how tall an element is, and it includes any extra space added by padding.

This example shows how to find the width and height inside a specific <div> element:


jQuery outerWidth() and outerHeight() Methods

The outerWidth() function tells you how wide an element is, including any extra space due to padding and borders.

The outerHeight() function tells you how tall an element is, and it includes both the padding and border in the measurement.

This example shows how to find the width and height of a specific <div> element's outer dimensions:

The outerWidth(true) function tells you how wide an element is, taking into account its padding, border, and margin.

The outerHeight(true) function tells you how tall an element is, taking into account its padding, border, and margin.


jQuery More width() and height()

This example shows how to find the size of both the web page (HTML document) and the visible area in the browser (viewport).

This example adjusts the size of a specific <div> element by setting its width and height.