6 ways to hide an element in CSS

Manthan Ankolekar - Jan 4 - - Dev Community

Here are six different ways to hide an element using CSS:

display: none;

.hidden-element {
  display: none;
}
Enter fullscreen mode Exit fullscreen mode

This completely removes the element from the document flow. It won't occupy any space on the webpage.

visibility: hidden;

.hidden-element {
  visibility: hidden;
}
Enter fullscreen mode Exit fullscreen mode

This hides the element, but it still occupies space on the webpage. The element is not visible, but the space it takes up remains.

opacity: 0;

.hidden-element {
  opacity: 0;
}
Enter fullscreen mode Exit fullscreen mode

This hides the element by making it fully transparent. It still occupies space and retains its dimensions but is visually hidden.

height: 0; width: 0; overflow: hidden;

.hidden-element {
  height: 0;
  width: 0;
  overflow: hidden;
}
Enter fullscreen mode Exit fullscreen mode

This hides the element by setting both its height and width to zero. Using overflow: hidden prevents any content from being visible.

clip-path: polygon(0 0, 0 0, 0 0, 0 0);

.hidden-element {
  clip-path: polygon(0 0, 0 0, 0 0, 0 0);
}
Enter fullscreen mode Exit fullscreen mode

This method uses the clip-path property to hide the element by defining a polygon shape with zero area.

clip-path: circle(0);

.hidden-element {
  clip-path: circle(0);
}
Enter fullscreen mode Exit fullscreen mode

This will hide the element by clipping it to a circle with no visible area, essentially making the element invisible.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player