5 November 2024

Get the total height of an element, optionally including its margins.

Source code viewer
  1. // The getBoundingClientRect().height method does not include margins. It only includes the element's height, padding, and borders.
  2. const height = element.getBoundingClientRect().height;
  3. const heightWithMargin = element.getBoundingClientRect().height
  4. + parseFloat(style.marginTop)
  5. + parseFloat(style.marginBottom);
Programming Language: Javascript