DEV Community

Manthan Ankolekar
Manthan Ankolekar

Posted on

8 1 1 1

6 ways to hide an element in CSS

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (2)

Collapse
 
ynn1k profile image
Yannik

This is just a 1:1 answer from ChatGPT, where it somehow managed to list the clip-path solution twice...
I got the position: absolute; left:-9999px as the 5th solution.

Collapse
 
hoj20 profile image
J.Has12

Thank'u for sharing

Some comments may only be visible to logged-in visitors. Sign in to view all comments.