# Check if an element has overflow

True when the content is larger than the element’s visible box.

Canonical: https://1loc.dev/dom/check-if-an-element-has-overflow/
Version: 1.0.0
Runtime: JavaScript · modern browsers (DOM)
Verification: Usage lines executed in headless Chromium against the fixture markup; no external services
Updated: 2026-10-28

## Implementation

```javascript
function hasOverflow(element) { return element.scrollHeight > element.clientHeight || element.scrollWidth > element.clientWidth; }
```

## Usage

Markup:

```html
<div id="box" style="height: 40px; overflow: hidden"><p style="height: 100px; margin: 0">Long content</p></div>
<div id="roomy" style="height: 200px"><p style="margin: 0">Short</p></div>
```

Script:

```javascript
hasOverflow(document.querySelector('#box')); // → true
hasOverflow(document.querySelector('#roomy')); // → false
```

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

## Limits

- Compares content size with the visible box, whatever the overflow style: use it to decide whether to show a “Show more” control.
- The sizes are rounded to integers, so sub-pixel overflow is missed. Elements with display: none report 0 for both.

The function does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/check-if-an-element-has-overflow.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.
