Performance: Visibility property
Controls whether an element is visible or hidden without removing it from the layout, affecting paint and compositing.
Jump into concepts and practice - no test required
element.style.visibility = 'hidden';
element.style.display = 'none';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| visibility:hidden | No DOM changes | 0 reflows | Paints hidden element (medium cost) | [OK] |
| display:none | No DOM changes | 1 reflow per element hidden | No paint for hidden element | [OK] Good |
visibility: hidden; do to an element on a webpage?visibility property controls whether an element is visible or hidden but does not affect layout space.hiddenhidden, the element is not shown but still occupies space on the page.: between property and value, ending with a semicolon.visibility: hidden; to hide but keep space.<div style="visibility: hidden; background: red; width: 100px; height: 100px;">Box</div>
visibility: hidden; hides the element but keeps its space on the page..hidden-box { visibility = hidden; }: to assign values, not an equals sign =.visibility = hidden; which is invalid syntax and ignored by browsers.display: none; removes element and space, opacity: 0; hides visually but keeps clickable, position: absolute; left: -9999px; moves element off screen.visibility: hidden; hides element but keeps its space, keeping layout stable.