> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/browser/dom/type/document/size.md).

# document size

[🔰 JS](/web/js.md) ⟩ [browser](/web/browser.md) ⟩ [DOM](/web/browser/dom.md) ⟩ [types](/web/browser/dom/type.md) ⟩ [Document](/web/browser/dom/type/document.md) ⟩ size

{% hint style="success" %} <mark style="color:purple;">**document size**</mark>

* width: <mark style="color:blue;">`document.documentElement.offsetWidth`</mark>
* height: <mark style="color:blue;">`document.documentElement.offsetHeight`</mark>
  {% endhint %}

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
[.offsetWidth](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth), [.offsetHeight](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight) will round the value to an <mark style="color:yellow;">**integer**</mark>. If you need a <mark style="color:orange;">**fractional**</mark> value, use [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
{% endhint %}

{% hint style="success" %}

* [.clientWidth](https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth)/[.clientHeight](https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight) = content + padding
* [.offsetWidth](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth)/[.offsetHeight](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight) = contnet + padding + <mark style="color:yellow;">**border**</mark>
* [.scrollWidth](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth)/[.scrollHeight](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight) = content + padding + <mark style="color:orange;">**overflow**</mark>
  {% endhint %}
  {% endtab %}

{% tab title="💈範例" %}

```javascript
// document size
const doc = {
    get width() { return document.documentElement.offsetWidth },
    get height() { return document.documentElement.offsetHeight },
};
```

{% endtab %}

{% tab title="👥 相關" %}

* [box models](/web/browser/dom/type/element/boxes.md)
* [Element+boxes](/web/browser/dom/type/element/+boxes.md)
* [viewport](/web/browser/dom/type/window/viewport.md) size.
* [.paddingBox](/web/browser/dom/type/element/+boxes/padding.md) of [HTMLElement](/web/browser/dom/type/htmlelement.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [ ] [HTML vs Body: How to Set Width and Height for Full Page Size](https://www.freecodecamp.org/news/html-page-width-height/)
  {% endtab %}

{% tab title="📘 手冊" %}

* [Document](/web/browser/dom/type/document.md) ⟩ [.documentElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/documentElement) (the \<html> element)
* [.borderBox](/web/browser/dom/type/element/+boxes/border.md) of [HTMLElement](/web/browser/dom/type/htmlelement.md)
  {% endtab %}
  {% endtabs %}
