# Get height and  width of an element using JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Aug 12, 2020, updated Sep 23, 2021. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-dom-get-height-and-width-of-an-element

> Learn how to get the height and width of an HTML element by using offsetHeight and offsetWidth properties in JavaScript.

To get the height and width of an HTML element, you can use the `offsetHeight` and `offsetWidth` properties.

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:

```javascript
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 `clientWidth` and `clientHeight` properties:

```javascript
const pizza = document.querySelector('.pizza');

const height = pizza.clientHeight;
const width = pizza.clientWidth;
```
