# Check if an element has CSS overflow

True when either axis is styled to scroll: overflow auto or scroll.

Canonical: https://1loc.dev/dom/check-if-an-element-has-css-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 hasCssOverflow(element) { const { overflowX, overflowY } = getComputedStyle(element); return [overflowX, overflowY].some(value => ['auto', 'scroll'].includes(value)); }
```

## Usage

Markup:

```html
<div id="panel" style="overflow-x: hidden; overflow-y: auto; height: 50px"></div>
<div id="plain"></div>
```

Script:

```javascript
hasCssOverflow(document.querySelector('#panel')); // → true
hasCssOverflow(document.querySelector('#plain')); // → false
getComputedStyle(document.querySelector('#panel')).overflow; // → 'hidden auto'
```

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

- The original read the overflow shorthand, which is "hidden auto" when the axes differ, as the last line shows; reading overflowX and overflowY handles both.
- This says whether the element would scroll, not whether its content overflows; see Check if an element has overflow.

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-css-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: Reads overflowX and overflowY; the original's shorthand check failed when the axes differ. Executed in Chromium. Original MDX retained as inert source evidence.
