CSS visibility Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
UI & Interaction

What You’ll Learn

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.

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.

📝 Syntax

The syntax for the visibility property is straightforward. It can be applied to any HTML element.

syntax.css
element {
  visibility: visible | hidden | collapse | inherit;
}

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

🎯 Default Value

The default value of the visibility property is visible, meaning the element is visible by default.

⚡ Quick Reference

QuestionAnswer
Default valuevisible
Hide but keep spacevisibility: hidden;
Remove from layoutdisplay: none; (not visibility)
Hide table row spacevisibility: collapse;
InheritedYes
Affects layout boxYes for hidden; no space removed

💎 Property Values

The visibility property accepts keyword values that control whether content is shown.

ValueExampleDescription
visiblevisibility: visible;The element is visible (default).
hiddenvisibility: hidden;The element is hidden, but still takes up space in the layout.
collapsevisibility: collapse;For table rows, columns, and groups, the element is hidden and its space is removed from the table layout.
inheritvisibility: inherit;The element inherits the visibility value from its parent.
visible hidden collapse inherit

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.

👀 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

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>

<p class="hidden-paragraph">
  This paragraph is hidden but still takes up space.
</p>
<p>This paragraph is visible.</p>
Try It Yourself

How It Works

hidden makes the paragraph invisible, but its box still occupies vertical space so the visible paragraph does not move up.

Example 2 — visibility vs display

Compare visibility: hidden with display: none side by side to see the layout difference.

compare.css
.vis-hidden { visibility: hidden; }
.disp-none { display: none; }
Try It Yourself

How It Works

visibility: hidden preserves the element’s box. display: none removes it entirely so siblings reflow.

📄 UI Patterns

Toggle visibility in components and collapse table rows.

Example 3 — Toggle with a CSS class

Switch between hidden and visible on a details block to avoid layout jumps when showing extra info.

toggle.css
.details { visibility: hidden; }
.card.is-open .details { visibility: visible; }
Try It Yourself

How It Works

The reserved space for .details stays in the card, so toggling visibility does not shift the button or card height abruptly.

Example 4 — Collapse a table row

Use visibility: collapse on table rows to hide them and remove their space from the table grid.

collapse.css
tr.collapsed {
  visibility: collapse;
}
Try It Yourself

How It Works

On table rows, collapse behaves like removing the row from the table while keeping the DOM structure intact for scripting.

♿ Accessibility

  • Hidden is not enough for screen readersvisibility: 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.

visibility vs display vs opacity

Choose the tool that matches your layout and interaction needs. These three properties are often confused by beginners.

PropertyVisibleTakes spaceInteractive
visibility: hiddenNoYesCan be (unless disabled)
display: noneNoNoNo
opacity: 0No (transparent)YesYes (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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support

Testing tip

Verify table collapse behavior in your target browsers when hiding rows dynamically with JavaScript.

visibility property 99% supported

Bottom line: visibility is safe to use for hiding content while preserving layout on the modern web.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about visibility

Use these points when showing or hiding content.

5
Core concepts
🕐 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.

Practice in the Live Editor

Open the HTML editor and compare visibility, display, and opacity side by side.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful