...
`).
````
## clientTop/Left
Inside the element we have the borders.
To measure them, there are properties `clientTop` and `clientLeft`.
In our example:
- `clientLeft = 25` -- left border width
- `clientTop = 25` -- top border width

...But to be precise -- they are not borders, but relative coordinates of the inner side from the outer side.
What's the difference?
It becomes visible when the document is right-to-left (the operation system is in arabic or hebrew languages). The scrollbar is then not on the right, but on the left, and then `clientLeft` also includes the scrollbar width.
In that case `clientLeft` in our example would be not `25`, but with the scrollbar width `25+16=41`:

## clientWidth/Height
These properties provide the size of the area inside the element borders.
They include the content width together with paddings, but without the scrollbar:

On the picture above let's first consider `clientHeight`: it's easier to evaluate. There's no horizontal scrollbar, so it's exactly the sum of what's inside the borders: CSS-height `200px` plus top and bottom paddings (`2*20px`) total `240px`.
Now `clientWidth` -- here the content width is not `300px`, but `284px`, because `16px` are occupied by the scrollbbar. So the sum is `284px` plus left and right paddings, total `324px`.
**If there are no paddings, then `clientWidth/Height` is exactly the content area, inside the borders and the scrollbar (if any).**

So when there's no padding we can use `clientWidth/clientHeight` to get the content area size.
## scrollWidth/Height
- Properties `clientWidth/clientHeight` only account for the visible part of the element.
- Properties `scrollWidth/scrollHeight` also include the scrolled out (hidden) part:

On the picture above:
- `scrollHeight = 723` -- is the full inner height of the content area including the scrolled out part.
- `scrollWidth = 324` -- is the full inner width, here we have no horizontal scroll, so it equals `clientWidth`.
We can use these properties to expand the element wide to its full width/height.
Like this:
```js
// expand the element to the full content height
element.style.height = element.scrollHeight + 'px';
```
```online
Click the button to expand the element:
, we can read CSS-height and width using `getComputedStyle`.
So why not to read the width of an element like this?
```js run
let elem = document.body;
alert( getComputedStyle(elem).width ); // show CSS width for elem
```
Why we should use geometry properties instead? There are two reasons:
1. First, CSS width/height depend on another property: `box-sizing` that defines "what is" CSS width and height. A change in `box-sizing` for CSS purposes may break such JavaScript.
2. Second, CSS `width/height` may be `auto`, for instance for an inline element:
```html run
Hello!
```
From the CSS standpoint, `width:auto` is perfectly normal, but in JavaScript we need an exact size in `px` that we can use in calculations. So here CSS width is useless at all.
And there's one more reason: a scrollbar. Sometimes the code that works fine without a scrollbar starts to bug with it, because a scrollbar takes the space from the content in some browsers. So the real width available for the content is *less* than CSS width. And `clientWidth/clientHeight` take that into account.
...But with `getComputedStyle(elem).width` the situation is different. Some browsers (e.g. Chrome) return the real inner width, minus the scrollbar, and some of them (e.g. Firefox) -- CSS width (ignore the scrollbar). Such cross-browser differences is the reason not to use `getComputedStyle`, but rather rely on geometry propeties.
```online
If your browser reserves the space for a scrollbar (most browsers for Windows do), then you can test it below.
[iframe src="cssWidthScroll" link border=1]
The element with text has CSS `width:300px`.
On a Desktop Windows OS, Firefox, Chrome, Edge all reserve the space for the scrollbar. But Firefox shows `300px`, while Chrome and Edge show less. That's because Firefox returns the CSS width and other browsers return the "real" width.
```
Please note that the described difference are only about reading `getComputedStyle(...).width` from JavaScript, visually everything is correct.
## Summary
Elements have the following geometry properties:
- `offsetParent` -- is the nearest positioned ancestor or `td`, `th`, `table`, `body`.
- `offsetLeft/offsetTop` -- coordinates relative to the left-upper edge of `offsetParent`.
- `offsetWidth/offsetHeight` -- "outer" width/height of an element including borders.
- `clientLeft/clientTop` -- the distance from the left-upper outer corner to its left-upper inner corner. For left-to-right OS they are always the widths of left/top borders. For right-to-left OS the vertical scrollbar is on the left so `clientLeft` includes its width too.
- `clientWidth/clientHeight` -- the width/height of the content including paddings, but without the scrollbar.
- `scrollWidth/scrollHeight` -- the width/height of the content including the scrolled out part. Also includes paddings, but not the scrollbar.
- `scrollLeft/scrollTop` -- width/height of the scrolled out part of the element, starting from its left-upper corner.
All properties are read-only except `scrollLeft/scrollTop`. They make the browser scroll the element if changed.
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
```
## scrollLeft/scrollTop
Properties `scrollLeft/scrollTop` are the width/height of the hidden, scrolled out part of the element.
On the picture below we can see `scrollHeight` and `scrollTop` for a block with a vertical scroll.

In other words, `scrollTop` is "how much is scrolled up".
````smart header="`scrollLeft/scrollTop` can be modified"
Most geometry properties that are read-only, but `scrollLeft/scrollTop` can be changed, and the browser will scroll the element.
```online
If you click the element below, the code `elem.scrollTop+=10` executes. That makes the element content scroll `10px` below.
Click
Me
1
2
3
4
5
6
7
8
9
```
Setting `scrollTop` to `0` or `Infinity` will make the element scroll to the very top/bottom respectively.
````
## Don't take width/height from CSS
We've just covered geometry properties of DOM elements. They are normally used to get widths, heights and calculate distances.
But as we know from the chapter Me
1
2
3
4
5
6
7
8
9