The visibility property lets you hide elements visually while keeping their space in the layout — useful when you want zero reflow.
01
Hide visually
Without removing space.
02
Syntax
visible, hidden, collapse.
03
visible
Default value.
04
vs display
Layout difference.
05
Tables
collapse rows.
06
A11y
Focus and screen readers.
Fundamentals
Introduction
The visibility property in CSS is used to control the visibility of an element. Unlike the display property, which removes the element from the document flow, visibility hides an element but still maintains its allocated space on the page.
This can be useful in situations where you want to hide an element without causing layout changes.
Definition and Usage
Apply visibility to any element when you need to toggle appearance while preserving layout structure. Common use cases include placeholder slots, skeleton states, and toggling details panels where reflow would feel jumpy.
💡
Beginner Tip
If you want to completely remove an element from the page layout, use display: none. Use visibility: hidden when the empty space should remain so surrounding content does not shift.
Foundation
📝 Syntax
The syntax for the visibility property is straightforward. It can be applied to any HTML element.
Here, the value can be one of several predefined keywords.
Basic Example
visibility.css
.hidden-paragraph{visibility:hidden;}
Syntax Rules
One keyword value at a time.
hidden keeps the element’s box in the layout.
Children can become visible even when a parent is hidden.
collapse is mainly for table rows, columns, and row/column groups.
The property is inherited.
Related Properties
display — removes or changes layout participation (none removes space)
opacity — fades content but keeps it interactive at values above 0
content-visibility — skips rendering off-screen content for performance
aria-hidden — accessibility attribute to hide content from assistive tech
Defaults
🎯 Default Value
The default value of the visibility property is visible, meaning the element is visible by default.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Default value
visible
Hide but keep space
visibility: hidden;
Remove from layout
display: none; (not visibility)
Hide table row space
visibility: collapse;
Inherited
Yes
Affects layout box
Yes for hidden; no space removed
Reference
💎 Property Values
The visibility property accepts keyword values that control whether content is shown.
Value
Example
Description
visible
visibility: visible;
The element is visible (default).
hidden
visibility: hidden;
The element is hidden, but still takes up space in the layout.
collapse
visibility: collapse;
For table rows, columns, and groups, the element is hidden and its space is removed from the table layout.
inherit
visibility: inherit;
The element inherits the visibility value from its parent.
visiblehiddencollapseinherit
Context
When to Use visibility
visibility is helpful when hiding should not disturb layout:
Reserved placeholders — Keep a slot open while content loads or toggles.
Stable toolbars — Hide labels or icons without shifting neighboring controls.
Table rows — Use collapse to hide rows and reclaim table space.
Print styles — Hide decorative elements while preserving document structure.
Animation handoff — Pair with transitions when fading before removing from layout.
Preview
👀 Live Preview
Three panels with the middle one visible, hidden (space kept), or removed with display: none:
Panel A
Panel B
Panel C
All visible
Panel A
Panel B
Panel C
visibility: hidden
Panel A
Panel B
Panel C
display: none
Hands-On
Examples Gallery
In this example, we’ll use the visibility property to hide a paragraph.
📜 Core Patterns
Hide content visually while understanding how layout space is affected.
Example 1 — Hide a paragraph
In this example, we’ll use the visibility property to hide a paragraph.
index.html
<style>.hidden-paragraph{visibility:hidden;}</style><pclass="hidden-paragraph">
This paragraph is hidden but still takes up space.
</p><p>This paragraph is visible.</p>
On table rows, collapse behaves like removing the row from the table while keeping the DOM structure intact for scripting.
A11y
♿ Accessibility
Hidden is not enough for screen readers — visibility: hidden hides content visually, but pair with aria-hidden="true" when content should be ignored by assistive technology.
Manage keyboard focus — Hidden elements may still receive focus. Use tabindex="-1" or move focus when hiding interactive controls.
Prefer display or inert for true removal — When content should be fully unavailable, display: none or the inert attribute is often safer.
Do not hide essential instructions — Only hide supplementary UI; critical labels and errors must stay visible or be announced another way.
Companion
visibility vs display vs opacity
Choose the tool that matches your layout and interaction needs. These three properties are often confused by beginners.
Property
Visible
Takes space
Interactive
visibility: hidden
No
Yes
Can be (unless disabled)
display: none
No
No
No
opacity: 0
No (transparent)
Yes
Yes (still clickable)
🧠 How visibility Works
1
Element exists in the DOM
The box is laid out normally in the document.
Layout
2
visibility changes rendering
hidden skips painting the element while keeping its box.
Paint
3
Surrounding layout stays stable
Neighbors keep their positions unlike display: none.
Reflow
=
✅
Hidden but spaced
Content disappears without collapsing the layout.
Compatibility
Browser Compatibility
The visibility property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. Testing across browsers is still recommended, especially for collapse in complex tables.
✓ Modern browsers · Widely supported
Show, hide, and collapse
visible and hidden work consistently everywhere. collapse is well supported for table elements.
99%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
Testing tip
Verify table collapse behavior in your target browsers when hiding rows dynamically with JavaScript.
visibility property99% supported
Bottom line:visibility is safe to use for hiding content while preserving layout on the modern web.
Wrap Up
Conclusion
The visibility property is a useful tool for controlling the visibility of elements on a web page without removing them from the document flow.
By understanding and using this property, you can create more dynamic and responsive layouts that maintain their structure even when certain elements are hidden. Experiment with the different values of the visibility property to see how they can be applied to your web designs.
Use visibility: hidden when layout must stay stable
Use collapse for hiding table rows and columns
Combine with aria-hidden for accessibility when appropriate
Choose display: none when space should be reclaimed
Test focus behavior when hiding interactive elements
❌ Don’t
Assume hidden removes content from the accessibility tree
Use visibility when you need zero layout footprint
Confuse visibility with opacity: 0 for click blocking
Hide critical error messages or form labels from users
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about visibility
Use these points when showing or hiding content.
5
Core concepts
📚01
Hidden = space kept
Layout stays put.
Purpose
🕐02
visible
Default value.
Default
🔀03
vs display
Reflow difference.
Compare
🔒04
collapse
Table rows.
Tables
🌐05
Inherited
From parent.
Cascade
❓ Frequently Asked Questions
visibility controls whether an element is visible. hidden hides the element visually but keeps its space in the layout.
The default value is visible, meaning the element is shown normally.
visibility hidden hides the element but keeps its space. display none removes the element from layout entirely so surrounding content reflows.
Yes, visibility is inherited. A child can override a hidden parent by setting visibility: visible.
collapse hides table rows, columns, or groups and removes their space from the table layout. Support varies slightly by browser for non-table elements.