How Does display: none Differ From visibility: hidden?

While both display: none and visibility: hidden hide elements on a webpage, they handle document layout, performance, user interaction, and accessibility in fundamentally different ways. The primary distinction lies in space allocation: display: none removes the element entirely from the document flow as if it does not exist, whereas visibility: hidden hides the element visually while preserving its physical dimensions and position on the page.

Document Flow and Layout Space

The most immediate visual difference between the two properties is how the surrounding content responds:

DOM Presence and the Render Tree

Both properties leave the affected HTML elements inside the Document Object Model (DOM), meaning JavaScript can still query and manipulate them using methods like document.querySelector(). However, their treatment in browser rendering engines differs:

Inheritance and Child Elements

The behavior of nested child elements differs significantly between the two rules:

User Interaction and Event Listeners

Hiding an element also changes how user inputs and pointer interactions are processed:

CSS Transitions and Animations

When building UI animations, each property provides different levels of support:

Accessibility and Screen Readers

Neither property is intended for creating accessible, visually-hidden content (such as screen-reader-only labels):

Quick Comparison

Feature display: none visibility: hidden
Layout Space Collapsed (takes no space) Preserved (leaves blank space)
Render Tree Excluded Included
Child Overrides Cannot be made visible Children can use visibility: visible
Browser Performance Triggers reflow and repaint Triggers repaint only
CSS Transitions Not animatable Supports transition delays
Accessibility Tree Removed completely Removed completely