CSS Visibility Property
The visibility property controls whether an element is visible while maintaining its space in the document layout, offering distinct behavior from the display property.
Understanding Visibility Values
The visibility property accepts three main values, each serving different use cases in web development.
Visibility: Visible
The default state where elements are fully rendered and visible to users.
Visibility: Hidden
Hides the element while preserving its layout space. The element becomes invisible but still occupies the same area in the document flow.
Visibility: Collapse
Primarily used for table rows and columns, removing the element while collapsing the space it occupied.
Visibility vs Display: None
The key distinction between visibility: hidden and display: none lies in layout preservation. Hidden elements retain their space while display: none removes elements entirely from the flow.
Practical Use Cases
Placeholder Layouts
Visibility hidden works perfectly for maintaining layout stability when content loads dynamically.
Hover Effects
Create interactive effects where hidden content appears on user interaction.
Child Element Visibility
Unlike display: none, visibility can be overridden by child elements. A visible child inside a hidden parent can still appear.
Accessibility Considerations
Elements with visibility: hidden are removed from the accessibility tree, making them invisible to screen readers. For accessible hiding that preserves screen reader access, consider alternative techniques covered in our CSS Accessibility guide.
Combining with Transitions
Since visibility is an animatable property, combine it with opacity for smooth fade effects as demonstrated in our CSS Transitions article.
Understanding when to use visibility versus display gives you precise control over element rendering and layout behavior in your designs.