To get the height and width of an HTML element, you can use the
These properties return the viewable height and width of an element in pixels, including border, padding, and scrollbar, but not the margin.
Here is an example:
const pizza = document.querySelector('.pizza'); const height = pizza.offsetHeight; const width = pizza.offsetWidth;
To skip the border and scrollbar, and get the width and height that just include padding, you can use the
const pizza = document.querySelector('.pizza'); const height = pizza.clientHeight; const width = pizza.clientWidth;