Skip to main content

CSS Hide Elements

You can hide elements with CSS using the display or visibility property.


CSS display: none;

With display: none, the element is completely removed from the document flow and takes up no space.

It is often used together with JavaScript to show or hide elements without deleting and recreating them.


Hide an Element - Use display:none or visibility:hidden?

You can hide an element by setting display: none. The element is hidden and the page is shown as if it were not there.

You can also use visibility: hidden to hide an element. With this property the element is hidden, but it still takes up the same space as before.

display: none

The hidden heading disappears and takes up no space.

Prompt
An HTML page that hides an element with display: none. In an internal <style> block, set h1.hidden { display: none; }. Add two headings: one normal and one with class "hidden". The hidden one disappears and takes up no space.
Output: complete HTML page

visibility: hidden

The hidden heading disappears but still takes up its space.

Prompt
An HTML page that hides an element with visibility: hidden. In an internal <style> block, set h1.hidden { visibility: hidden; }. Add two headings: one normal and one with class "hidden". The hidden one disappears but still takes up its space.
Output: complete HTML page

CSS Display/Visibility Properties

A summary of the properties used here:

  • display — sets how an element is displayed; none removes it from the flow.
  • visibility — sets whether an element is visible; hidden hides it but keeps its space.