# .checkVisibility()

> The `.checkVisibility()` JS method checks whether an element is potentially visible.

## How do I check if an element is visible in JavaScript?

The method that returns `false` if the element is not rendered, for example because of 'display: none' or `content-visibility`, and `true` otherwise. Options allow also checking `opacity` and `visibility`.

- Topic: Object on Page
- Type: method
- Browser support: Chrome 105+, Chrome Android 105+, Edge 105+, Firefox 106+, Firefox Android 106+, Safari 17.4+, Safari iOS 17.4+

## Example

Wrong:

```js
function isVisible(el) {
  return el.offsetParent !== null;
}
```

Right:

```js
function isVisible(el) {
  return el.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true });
}
```

`offsetParent` is also `null` for fixed elements; `checkVisibility()` checks display, visibility and opacity.

## Common mistakes

- Expecting `false` for an element scrolled out of view.

## Key points

- `checkVisibility()` is used instead of checks like `offsetParent !== null`.
- Options like `checkOpacity` and `checkVisibilityCSS` are passed when those cases matter.
- Checking whether the element is in the viewport uses `IntersectionObserver`, not `checkVisibility()`.

## Interview questions

### Does checkVisibility tell if an element is in the viewport?

No. It returns `true` for an element scrolled off screen. Use `IntersectionObserver` to check the viewport.

### What does checkVisibility check by default?

It returns `false` when the element or an ancestor has `display: none` or `content-visibility: hidden`. Opacity and `visibility` are checked only on request.

## Related cards

- [IntersectionObserver](https://wonderium.dev/js/intersection-observer.md)
- [visibility](https://wonderium.dev/css/visibility.md)
- [display](https://wonderium.dev/css/display.md)
- [content-visibility](https://wonderium.dev/css/content-visibility.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/check-visibility
- Last updated: 2026-11-25
