Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

visibility

Hides an element but keeps the space it occupies.

Syntax

visibility: hidden;

Values

ParameterTypeDescription
visiblekeywordVisible (the default).
hiddenkeywordInvisible, but the space stays.
collapsekeywordFor table rows and columns — hides them like `display: none`.

Examples

visibility: hidden leaves a gap, display: none does not:

<style>
  span { background: lavender; padding: 4px; }
</style>
 
<p><span>One</span> <span style="visibility: hidden;">Two</span> <span>Three</span></p>
<p><span>One</span> <span style="display: none;">Two</span> <span>Three</span></p>

Notes

A hidden element cannot be clicked and is not read by screen readers. Unlike display, visibility can be animated with transition, which is handy for menus that fade in and out.

See also

  • display — Decides how an element behaves in the flow and how it lays out its content.
  • opacity — The transparency of the whole element together with its content.

Related recipes

In the tutorial

  • The display property — Block and inline elements, the values block, inline, inline-block and none, hiding elements.

Thanks for reading!

Donate to the site — we work hard for you.