CSS visibility Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The visibility property shows or hides an element. With hidden, the box is not drawn but still occupies layout space. Neighbors do not slide into the gap.

To hide an element and remove its space, use display: none instead. The property is inherited. The initial value is visible.

Baseline · Widely available.

Not deprecated. hidden also removes the element from the accessibility tree and from keyboard focus.

Experimental:

force-hidden appears in newer CSS Display drafts (hide ancestors so children cannot re-show). Skip it for production until browsers ship it as a CSS value.

CSS Syntax

syntax.css
visibility: visible | hidden | collapse;

Example: visibility: hidden;

Property Values

ValueDescriptionTry it
visibleShown normally. Initial valueTry it
hiddenInvisible, but layout space remainsTry it
collapseHides table rows/columns and removes their space; like hidden on most other elementsTry it
initialResets to visibleTry it
inheritTakes the parent’s visibilityTry it

How to Use visibility

Choose whether to keep layout space, then set the keyword on the element.

  1. Decide: hide but keep space (hidden) or remove from layout (display: none).
  2. Set visibility on the element you want to show or hide.
  3. Optional: show a child inside a hidden parent with visibility: visible on that child.
  4. For table rows or columns, consider collapse when you want to drop their space without a full table reflow.
PieceRequired?Role
Target elementYesThe box to show or hide
KeywordYesvisible, hidden, or collapse
Layout goal—Keep space vs remove space vs table collapse

Live Preview

Three boxes in a row. Change visibility on the middle box and watch whether the gap stays.

On a normal box, collapse usually looks like hidden. Use a table row to see true collapse.

Boxes
A
B
C

visibility: visible

CSS Examples

Each snippet focuses on visibility. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Hide but Keep Space

The middle box disappears; A and C stay apart.

CSS
<style>
  .b {
    visibility: hidden;
  }
</style>

<div>A</div>
<div class="b">B</div>
<div>C</div>
Try It Yourself

How It Works

  1. Hide B. visibility: hidden stops painting the middle box.
  2. Space stays. The layout still reserves room for B.
  3. Neighbors stay put. A and C do not move together.
  4. Compare with display. display: none on B would let C slide left.

Example 2 — Show a Child Inside Hidden

Because visibility is inherited, a child can become visible again.

CSS
<style>
  .parent {
    visibility: hidden;
  }
  .child {
    visibility: visible;
  }
</style>

<div class="parent">
  Parent hidden
  <span class="child">Child visible</span>
</div>
Try It Yourself

How It Works

  1. Parent is hidden. Its own text is not painted.
  2. Child overrides. visibility: visible on the child shows that child.
  3. Inheritance matters. Without the override, the child would stay hidden too.
  4. Unlike display: none. A child cannot reappear if the parent uses display: none.

Example 3 — Collapse a Table Row

Hide a row and remove its vertical space from the table.

CSS
<style>
  .hide {
    visibility: collapse;
  }
  td {
    border: 1px solid #ccc;
    padding: 8px;
  }
</style>

<table>
  <tr><td>Row 1</td></tr>
  <tr class="hide"><td>Row 2</td></tr>
  <tr><td>Row 3</td></tr>
</table>
Try It Yourself

How It Works

  1. Target the row. visibility: collapse on tr hides Row 2.
  2. Space drops. Unlike hidden, the row’s height is removed from the table.
  3. Sizing can stay. Other columns may still size as if those cells existed.
  4. Not for every box. On a normal div, collapse usually acts like hidden.

Edge Cases & Pitfalls

If hide/show behaves oddly, one of these is usually why.

display

Do not confuse with display: none

hidden keeps space. display: none removes the box from flow.

a11y

Hidden leaves the accessibility tree

Screen readers skip visibility: hidden content, and the element cannot receive focus.

opacity

Different from opacity: 0

opacity: 0 can still receive pointer events unless you also disable them. hidden is not interactive.

collapse

collapse quirks outside tables

On most non-table elements it matches hidden. Flex/ruby collapse behavior is incomplete in some engines.

child

Children can reappear

A visible descendant shows again inside a hidden ancestor. That does not work with display: none.

Browser Support

visibility is a browser CSS property for showing and hiding boxes. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

visibility

Supported in all major browsers for many years (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, IE 4+).

97% Global support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 4+
Full support
Samsung Internet 1+
Full support
Internet Explorer 4+
Full support
visibility Widely supported

Bottom line: Safe everywhere for visible/hidden. Prefer collapse mainly for table rows and columns. This is not a JavaScript runtime API.

Key Takeaways

  • Role: show or hide without removing layout space when using hidden.
  • vs display: none removes the box; hidden leaves a gap.
  • Inherited. A child can set visible inside a hidden parent.
  • collapse: best understood on table rows and columns.

One line: visibility: hidden makes a box invisible but still present in the layout.

Frequently Asked Questions

It shows or hides an element without removing it from document flow when you use hidden. The box is not painted, but it still takes up layout space.
hidden keeps the element’s space so neighbors do not move. display: none removes the box from layout, so content reflows into that space.
The initial value is visible.
Yes. A child can override a hidden ancestor by setting visibility: visible, which makes that child show again.
On table rows, columns, and groups it hides them and removes their space while still using their sizes for table layout. On most other elements it behaves like hidden.
It is Baseline Widely available and supported in all major browsers, including Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: white-space

Control how spaces, tabs, and line breaks are handled in text.

white-space tutorial →

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.

8 people found this page helpful