Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

visibility — hiding without removing layout space

The visibility property controls whether an element’s boxes are visible. hidden hides them while preserving layout space, and a descendant with visible can remain visible. collapse has layout-context-dependent behavior.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate; usage example matched expected output in isolated Chromium 157.0.8103.51

Syntax

visibility: visible | hidden | collapse | force-hidden;

visibility applies to all elements, is inherited, and initially equals visible. visible displays boxes normally; hidden hides them while preserving their participation in layout. In contrast, display: none prevents the element and its descendants from generating boxes.

A descendant can override inherited hidden with visibility: visible. Invisible boxes do not participate in pointer interaction or navigation. Avoid hiding semantic containers while leaving children visible, such as a table row with visible cells: the specification warns about accessibility-tool problems.

collapse can reduce occupied space according to the layout’s rules, notably for table rows and columns and for flex items. In other cases it behaves like hidden. Do not treat it as a universal replacement for display: none.

The CSS Display Level 4 draft adds force-hidden: it also hides descendants regardless of their visibility. This is a draft value; its inclusion in the specification’s syntax does not establish Chromium 152 support. The example uses only hidden and visible. It produced the expected output in an isolated run in Chromium 157.0.8103.51.

Examples

<!doctype html>
<meta charset="utf-8">
<title>visibility</title>
<style>
  #box { visibility: hidden; height: 40px; }
  #child { visibility: visible; }
</style>
<div id="box">Hidden text <span id="child">Visible child</span></div>
<div id="next">Next block</div>
<pre id="result"></pre>
<script>
  const box = document.getElementById('box');
  const child = document.getElementById('child');
  const next = document.getElementById('next');
  const rect = box.getBoundingClientRect();
  document.getElementById('result').textContent = [
    getComputedStyle(box).visibility,
    getComputedStyle(child).visibility,
    rect.height,
    next.getBoundingClientRect().top - rect.top
  ].join('\n');
</script>

Result

hidden
visible
40
40

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