Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

CSSStyleDeclaration.visibility: declared versus computed values

Read the result of the CSS cascade through getComputedStyle(element).visibility rather than element.style.visibility. Distinguish inline declarations, inheritance, and the live style object.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

element.style.visibility = "hidden";
window.getComputedStyle(element).visibility;
window.getComputedStyle(element).getPropertyValue("visibility");

CSSStyleDeclaration.visibility denotes named access to the CSS visibility property, not a separate computation method. Modern documentation places these properties on CSSStyleProperties, derived from CSSStyleDeclaration; older implementations use the base type.

element.style.visibility reads only the inline declaration: it may return "" or "inherit". window.getComputedStyle(element).visibility returns the resolved value after the cascade and inheritance. In general, a resolved value is not always the same as a computed value. Calling getPropertyValue("visibility") on the returned object is an equivalent read.

visibility is inherited. hidden hides an element while preserving its layout space; display: none removes that space. A descendant can explicitly set visible. collapse has special behavior in contexts including tables and has cross-browser limitations. A result of visible alone does not prove that the element is actually visible.

The object returned by getComputedStyle() is read-only and live: it updates when styles change. Modify element.style or CSS rules, not this object. This is a browser API, not a feature of a particular ECMAScript edition; Node 24 does not establish its availability. Basic reading is widely supported, independently of the newer interface name.

Examples

const parent = document.createElement("div");
const child = document.createElement("span");
parent.style.visibility = "hidden";
child.style.visibility = "inherit";
parent.append(child);
document.body.append(parent);

try {
  const computed = window.getComputedStyle(child);
  console.log(JSON.stringify(child.style.visibility));
  console.log(computed.visibility);
  child.style.visibility = "visible";
  console.log(computed.getPropertyValue("visibility"));
} finally {
  parent.remove();
}

Result

"inherit"
hidden
visible

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources