Element.checkVisibility() is an instance method that returns true or false depending on whether an element is potentially visible. Learn the default checks, optional opacityProperty and visibilityProperty flags, content-visibility behavior, and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Returns
true / false
03
Default
Box + content-visibility
04
Options
opacity, visibility, auto
05
Not a guarantee
May be off-screen
06
Status
Baseline 2024
Fundamentals
Introduction
Before checkVisibility(), developers often guessed visibility with tricks like offsetParent or measuring getBoundingClientRect(). Those heuristics miss edge cases and do not understand modern CSS such as content-visibility.
checkVisibility() gives you one standardized boolean answer. By default it returns false when the element has no layout box (for example display: none or display: contents) or when content-visibility: hidden applies on the element or an ancestor.
💡
Beginner tip
A return value of true means the element may be visible—not that the user is definitely looking at it. Elements outside the viewport or hidden behind other layers can still return true.
Calling el.checkVisibility() runs a set of visibility rules and returns a boolean. Pass an optional options object when you need stricter checks for opacity, visibility, or content-visibility: auto skip rendering.
It is an instance method on Element.
Default checks: associated box exists; no content-visibility: hidden on self or ancestors.
Optional opacityProperty: true also fails when computed opacity is 0.
Optional visibilityProperty: true also fails for visibility: hidden or collapse.
Optional contentVisibilityAuto: true also fails when content-visibility: auto skips rendering.
Historic aliases: checkOpacity and checkVisibilityCSS.
Foundation
📝 Syntax
General form of Element.checkVisibility (MDN):
JavaScript
checkVisibility(options)
Parameters
options(optional) — an object with optional boolean flags: contentVisibilityAuto, opacityProperty (alias checkOpacity), visibilityProperty (alias checkVisibilityCSS). Each defaults to false.
Return value
false if any applicable check fails; otherwise true.
Common patterns
JavaScript
const el = document.getElementById("panel");
el.checkVisibility(); // default checks
el.checkVisibility({ opacityProperty: true }); // also test opacity: 0
el.checkVisibility({ visibilityProperty: true }); // also test visibility
el.checkVisibility({
opacityProperty: true,
visibilityProperty: true,
contentVisibilityAuto: true
});
Element.checkVisibility() is Baseline Newly available (MDN: across latest browsers since March 2024). Feature-detect on older engines. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline 2024
Element.checkVisibility()
Modern boolean visibility checks with optional opacity, visibility, and content-visibility flags.
BaselineNewly available 2024
Google ChromeSupported in current releases — feature-detect older
Yes
Microsoft EdgeSupported in current releases — feature-detect older
Yes
Mozilla FirefoxSupported in current releases — feature-detect older
Yes
Apple SafariSupported in current releases — feature-detect older
Yes
OperaFollow Chromium support
Yes
Internet ExplorerNo checkVisibility — use fallbacks
No
checkVisibility()Baseline
Bottom line: Prefer checkVisibility() over offsetParent heuristics in new code. Pass options when transparent or visibility:hidden elements should count as not visible, and always feature-detect for older browsers.
Wrap Up
Conclusion
Element.checkVisibility() is the standardized way to ask whether an element is potentially visible. Use the default check for layout boxes and content-visibility: hidden, then opt into stricter opacity and visibility rules when your UI logic needs them.
Pick options that match your definition of “visible”
Combine with Intersection Observer for viewport checks
Test content-visibility cases explicitly
Prefer this API over offsetParent in new code
❌ Don’t
Assume true means the user sees the element
Expect default check to catch opacity: 0
Call it without a fallback on very old browsers
Confuse visibility with pointer-events or aria-hidden
Replace intersection math when you need on-screen %
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.checkVisibility()
Potentially visible — not guaranteed on screen.
5
Core concepts
📝01
Returns
boolean
API
📄02
Default
box + cv:hidden
Core
✍️03
Options
opacity, visibility
Flags
✅04
Baseline
2024
Status
⚡05
Caveat
may be off-screen
Note
❓ Frequently Asked Questions
It returns a boolean indicating whether the element is potentially visible. By default it checks for an associated layout box and whether content-visibility: hidden applies. Optional flags can also test opacity: 0, visibility: hidden/collapse, and content-visibility: auto skip rendering.
No. MDN marks Element.checkVisibility() as Baseline Newly available (since March 2024). It is not Deprecated, Experimental, or Non-standard.
Not always. true means the element may be visible according to the checks you run. Elements outside the viewport or covered by other content can still return true.
offsetParent is an older heuristic that breaks for fixed positioning and some modern CSS. checkVisibility() is the standardized way to ask whether an element has a box and passes optional CSS visibility rules.
An optional object: opacityProperty (alias checkOpacity), visibilityProperty (alias checkVisibilityCSS), and contentVisibilityAuto. Each defaults to false.
Feature-detect with typeof el.checkVisibility === "function" and fall back to heuristics like getBoundingClientRect() or offsetParent only when needed.
Did you know?
opacity: 0 and visibility: hidden still leave a layout box, so the defaultcheckVisibility() call returns true. Enable opacityProperty or visibilityProperty when those should count as hidden.